- bind2nd with templates - 2 Updates
- boost::posix_time - 1 Update
Paul <pepstein5@gmail.com>: Jul 10 01:07AM -0700 On Thursday, July 9, 2015 at 8:04:14 PM UTC+1, Richard wrote: > member or method member), it needs the typename keyword. > This Stack Overflow post seems to explain it pretty well in more detail > <http://stackoverflow.com/a/613132/139855> Thanks, Richard. In other words, you need one typename declaration (not sure if "declaration" is the right word here. Feel free to correct if not) to state that <Type> refers to a type and another typename declaration to state that x<Type>::SomethingElse also refers to a type. Paul |
legalize+jeeves@mail.xmission.com (Richard): Jul 10 04:27PM [Please do not mail me a copy of your followup] Paul <pepstein5@gmail.com> spake the secret code >sure if "declaration" is the right word here. Feel free to correct if >not) to state that <Type> refers to a type and another typename >declaration to state that x<Type>::SomethingElse also refers to a type. Sure, let's go back and look at your code, reformatted slightly: template <typename RandomAccessIterator> // 1st use of typename keyword void quicksort(RandomAccessIterator begin, RandomAccessIterator end) { if (begin != end) { typdef typename std::iterator_traits<RandomAccessIterator>::value_type // 2nd use of typename keyword iterator_value_type; RandomAccessIterator pivot = std::partition(begin, end, bind2nd(std::less<iterator_value_type>(), *begin)); quicksort( begin, pivot); RandomAccessIterator new_pivot = begin; quicksort(++new_pivot, end); } } (Here, I've introduced a local typedef for the value type of the random access iterator that we got from std::iterator_traits.) When you write a template function, you have to tell the template mechanism what kind of template arguments are supplied to your template function. It was always allowed that you could write 'typename' or 'class' to indicate that the argument was expected to be a type and not an integral constant. 'class' seemed to be more commonly used in the past and over time the community has shifted to favoring the 'typename' because it is more intention-revealing than 'class'. (The supplied type need not be a class, it could be a builtin type like int, or it could be a struct or union.) This is how typename is used in the first location in your code. In the second location, we're instantiating a template with a type argument. That type argument comes from a nested name inside another template, in this case the other template is std::iterator_traits and the nested name is value_type. Here we need to use typename to tell the compiler that the nested name refers to a type and not a function or data member. (Note that the nested name needn't be a name introduced by a typedef but it often is. It could be a nested class or struct or union as well.) -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Jul 10 02:36AM +0200 On 10-Jul-15 12:50 AM, Christopher Pisz wrote: > meets the condition of, every 3rd week from 07/09/2015?" > so i figure something like > if( (currentdatetime - startdatetime).AsTotalWeeks() % 3 == 0) I read "the difference between two datetimes expressed as a total number of weeks" as "the difference between two datetimes, with the difference expressed as a total number of weeks". At the risk of stating the obvious, a week is always 7 days. But you need general calendar functionality to find the number of days between two dates. As of C++14 such calendar functionality is not provided by the standard library. You can go with a DIY solution based on the C library's [1]tm structure, which involves computing leap years etc., see <url: http://stackoverflow.com/questions/24403829/find-difference-between-two-dates-c>. Or you can go with one of the two Boost calendar sub-libraries, or perhaps platform specific functionality. Cheers & hth., - Alf Notes: [1] tm can be converted to time_t e.g. via mktime, which can be converted to std::chrono::whatever_clock via its from_time_t member function. See Josuttis' "The C++ Standard Library: A Tutorial and Reference" or the excerpt at <url: <url: http://www.informit.com/articles/article.aspx?p=1881386&seqNum=2>. -- Using Thunderbird as Usenet client, Eternal September as NNTP server. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment