Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Are default function parameters in allowed in function templates?

Reply
Thread Tools

Are default function parameters in allowed in function templates?

 
 
Ulrich Achleitner
Guest
Posts: n/a
 
      01-04-2005
On Tue, 04 Jan 2005 13:06:28 +0000, BRG <(E-Mail Removed)> wrote:

>>>>>> template<class T, class C> bool count(T x[], C cmp = std::less<T>())

>> this is never a correct place for a default _type_. in a function's
>> parameter list there can only be default _values_.

>
> Yes, but std::less<T> and std::less<T>() are values, not types, aren't
> they?


the former is a type, the latter is a value / object. sorry, i overlooked
the () in your original posting...
 
Reply With Quote
 
 
 
 
BRG
Guest
Posts: n/a
 
      01-04-2005
Ulrich Achleitner wrote:
> On Tue, 04 Jan 2005 13:06:28 +0000, BRG <(E-Mail Removed)> wrote:
>
>>>>>>> template<class T, class C> bool count(T x[], C cmp = std::less<T>())
>>>
>>> this is never a correct place for a default _type_. in a
>>> function's parameter list there can only be default _values_.

>>
>>
>> Yes, but std::less<T> and std::less<T>() are values, not types,
>> aren't they?

>
> the former is a type, the latter is a value / object. sorry, i
> overlooked the () in your original posting...


Thanks for taking an interest in this.

I have had to abandon defaults here as I cannot find a way of making
them work. What has worked as a way of inling the comparison code (to
avoid the overhead of a function call) is:

template<class T> inline bool
lt_f(const T& x, const T& y) { return x < y; }

template<class T, bool C(const T&, const T&)>
bool count(T x[]) { ... C(x[j], x[i]) ... }

...
int q[10];
count<int, lt_f<int> >(q);
...

But I have had to build my own comparison templates in place of those in
<functional>.

Thanks again for your input.

Brian Gladman
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why defining a constant in a method is not allowed but usingself.class.const_set is allowed? IƱaki Baz Castillo Ruby 13 05-01-2011 06:09 PM
Is it allowed to use function results as default arguments ? Stef Mientki Python 4 07-30-2008 03:14 PM
Mixing default and non-default parameters in Constructor? desktop C++ 2 06-06-2007 08:25 PM
Class Member Data and Member Function Parameters - Should Parameters Be Data Members? Jason C++ 2 05-13-2006 07:11 AM
Usage of default constructed slice allowed in valarray? [long] Clemens Hintze C++ 0 11-07-2005 12:46 PM



Advertisments