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,891 of 33,346   
   James K. Lowden to TomaszMikolajczyk   
   Re: template class with non-type-param t   
   07 Feb 12 01:44:56   
   
   d6236499   
   From: jklowden@speakeasy.net   
      
   On Mon,  6 Feb 2012 15:59:30 -0800 (PST)   
   TomaszMikolajczyk  wrote:   
      
   > template   
   > class Range   
   > {   
   > public:   
   >     /// PRECONDITION: min <= max.   
   >     Range(const T& min, const T& max) : _min(min), _max(max)   
   >     {   
   >         assert(min <= max);   
   >     }   
   >   
   >     template   
   >     Range() : _min(min), _max(max)   
   >     {   
   >         static_assert(min <= max, "invalid range");   
   >     }   
   >   
   >     const T& getMin() const { return _min; }   
   >     const T& getMax() const { return _max; }   
   > private:   
   >     T _min, _max;   
   > };   
      
   Does this get you where you're going instead?   
      
   template   
   class Range   
   {   
   public:   
       Range();   
   	....   
   };   
      
   That allows min/max to be set at runtime or compile time in a   
   conventional way.   
      
   Note that T cannot be just any type.  It can be integral or a pointer,   
   but not e.g. float.   
      
   --jkl   
      
      
   --   
         [ 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