home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,896 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to TomaszMikolajczyk   
   Re: template class with non-type-param t   
   08 Feb 12 00:48:53   
   
   226d4dd4   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-02-08 04:10, TomaszMikolajczyk wrote:   
   >>> Disadvantage: class CopyConstructible requirement.   
   >>   
   >> I don't understand your rationale. Which type needs to satisfy the   
   >> CopyConstructible requirements? From your original Range template we can   
   >> already deduce that you need to impose the CopyConstructible   
   >> requirements on T (assuming T is an object type). Without this   
   >> requirement you could not construct your _min and _max members anyway.   
   >   
   > TM: My apologize I was not clear and use a shorthand. I assumed   
   > possibility that a real class used in the app. is uncopyable   
   > (private copy ctor and assigment op.)   
      
   OK, that makes it clearer. With this additional constraint you might   
   want to consider the following approach:   
      
   template   
   struct Limits   
   {   
     static_assert(Min <= Max, "invalid range");   
   };   
      
   template   
   class RangeNoCopy   
   {   
   public:   
     RangeNoCopy(const T& min, const T& max) : _min(min), _max(max)   
     {   
       assert(min <= max);   
     }   
      
     template   
     RangeNoCopy(Limits) : _min(Min), _max(Max)   
     {   
     }   
      
     RangeNoCopy(const RangeNoCopy&) = delete;   
     RangeNoCopy& operator=(const RangeNoCopy&) = delete;   
      
     const T& getMin() const { return _min; }   
     const T& getMax() const { return _max; }   
   private:   
     T _min, _max;   
   };   
      
   RangeNoCopy r(Limits{});   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca