I trying to create a simple test for type that derive from a specific templated base. Here is the code.
#include <string>
template <class... T>
struct bar { };
struct foo : bar<>
{
template <class... T>
foo(T&&...) { }
};
template <class T>
struct is_bar {
private:
template <class... U>
static std::true_type test(bar<U...>);
static std::false_type test(...);
public:
static constexpr bool value = decltype(test(std::declval<T>()))::value;
};
template <class T>
void test(T&&) {
static_assert(is_bar<std::decay_t<T>>::value);
}
int main()
{
// Test 1: works
test(foo(std::string()));
// Test 2: works
std::string s;
foo f2(s);
test(f2);
// Test 3: not working
foo f3(std::string());
test(f3);
}
Tests 1 and 2 works fine. See comments. Can someone point out why test 3 result in a false assert?