Topic: implementing standard library functions with enable_if
Author: "msalters" <Michiel.Salters@logicacmg.com>
Date: Wed, 30 Mar 2005 23:05:51 CST Raw View
Chris Jefferson wrote:
> Is it valid to implement a standard library function (say find) as:
>
> template<class T, class val>
> enable_if<condition<T>::value, T> find(T,T,const val&);
>
> template<class T, class val>
> enable_if<!condition<T>::value, T> find(T,T,const val&);
>
> I can't see how this would be user visible, but I can't
> decide if that means it allowed.
Assuming you really mean __condition, and assuming you
mean something like enable_if<...>::type, I'd say it
doesnt matter how a type is named, just which type that
refers to.
Still, I'd expect this to be hidden inside the find
implementation
> Further, if it was allowed, would it be allowed to have no
> function match where the parameters given to find aren't
> legal (ie T is an output_iterator)?
Yes, there's no requirement /how/ an implementation has
to diagnose such failures.
HTH,
Michiel Salters
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: caj@cs.york.ac.uk (Chris Jefferson)
Date: Tue, 29 Mar 2005 11:37:11 GMT Raw View
Is it valid to implement a standard library function (say find) as:
template<class T, class val>
enable_if<condition<T>::value, T> find(T,T,const val&);
template<class T, class val>
enable_if<!condition<T>::value, T> find(T,T,const val&);
I can't see how this would be user visible, but I can't decide if that
means it allowed.
Further, if it was allowed, would it be allowed to have no function
match where the parameters given to find aren't legal (ie T is an
output_iterator)?
Chris
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Thu, 31 Mar 2005 01:17:55 GMT Raw View
Chris Jefferson wrote:
> Is it valid to implement a standard library function (say find) as:
>
> template<class T, class val>
> enable_if<condition<T>::value, T> find(T,T,const val&);
>
> template<class T, class val>
> enable_if<!condition<T>::value, T> find(T,T,const val&);
>
> I can't see how this would be user visible, but I can't decide if that
> means it allowed.
The library-wide requirements on global functions (17.4.4.3) say:
A call to a global function signature described in Clauses 18
through 27 behaves the same as if the implementation declares no
additional global function signatures.
which implies that only the function signatures need to match what
the standard specifies, and not the function templates. So I think
it's allowed.
> Further, if it was allowed, would it be allowed to have no function
> match where the parameters given to find aren't legal (ie T is an
> output_iterator)?
Givng a standard template a type argument that doesn't match
requirements set down in the standard results in UB (17.4.3.6/2), and
that includes the possibility of compile-time failure (1.3.12). So
I believe that would be legal.
--
Ben Hutchings
Humans are not rational beings; they are rationalising beings.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]