Re: why std::vector<T>&& is not a universal reference?
Am 09.10.2012 20:19, schrieb Daniel Kr?gler:
On 2012-10-09 15:16, Gennadiy Rozental wrote:
On Tuesday, October 9, 2012 12:30:03 AM UTC-4, Daniel Kr?gler wrote:
Am 09.10.2012 00:48, schrieb Gennadiy Rozental:
Any workarounds?
The usual technique is to specify a function of the form T&& and to
constrain it accordingly. E.g.
#include <vector>
#include <type_traits>
template<class T>
struct is_vector : std::false_type {};
template<class T>
struct is_vector<std::vector<T>> : std::true_type {};
While we on the subject, why doesn't standard type traits provide
this?
I don't think that this trait should be standardized, because it is
neither very complicated to write, nor do I see any general pattern in
it.
I would like to point out a further specification problem of your
original query that I didn't mention in my first response: You
specifically asked for the pattern std::vector<T> (and therefore
restricting to the default std::allocator<T>). This is sometimes right,
but sometimes it is not and you want the more general
template<class T, class A>
struct is_vector<std::vector<T, A>> : std::true_type {};
I only mention that, because I want to point out there is not necessary
a unique answer to your question. But this is only a side information, I
still think that it is usually better to detect types that satisfy
specific expression/member type criteria instead of specific template
patterns.
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! ]