On Tue, Sep 15, 2009 at 8:17 PM, Mark Zweers <zweers.m...@gmail.com> wrote:
>
> Hello,
>
> While experimenting with "Defaulted and deleting functions" on my brand-newly
> downloaded gcc-4.5 compiler, I've noticed the following: the order of
> '=default' and '=delete' matters with template member functions.
>
> template<typename T>
> class NonCopyable {
> public:
> NonCopyable();
> ~NonCopyable();
> NonCopyable(NonCopyable const&);
> };
>
> template<typename T>
> NonCopyable<T>::NonCopyable() = default;
>
> template<typename T>
> NonCopyable<T>::~NonCopyable() = default;
>
> template<>
> NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete;
>
> template<typename T>
> NonCopyable<T>::NonCopyable(NonCopyable<T> const&) = default;
>
>
> int main()
> {
> NonCopyable<int> nc_int;
> NonCopyable<int> nc_int_cpy(nc_int);
>
> NonCopyable<double> nc_dbl;
> NonCopyable<double> nc_dbl_cpy(nc_dbl);
>
> return 0;
> }
>
> The above example results in the sought behavior : only for a 'double'
> specialisation the copy constructor is prohibited.
>
> However, if I reverse the order of copy constructors, nothing is prohibited
> at all (deletion of the 'double' specialisation is useless) :
>
> template<typename T>
> NonCopyable<T>::NonCopyable(NonCopyable<T> const&) = default;
>
> template<>
> NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete;
>
> although this would seem to me to be a more likely use case : the general
> case is provided ; in another, separate file, prohibition of the copy
> constructor is specialized.
>
> What is your opinion about this?
>
> Thank you a lot for your answer!
>
> Bests,
>
> Mark Zweers