相关文章推荐
飘逸的登山鞋  ·  Qt ...·  11 月前    · 
直爽的机器人  ·  SQL ...·  1 年前    · 
帅呆的马克杯  ·  Hive SQL(5)-lateral ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

It is giving me an error

error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
     using enable_if_t = typename enable_if<_Cond, _Tp>::type;

It I don't put getX() and getY() inside struct B it works. However, if I put them both inside a struct then it doesn't.

#include <iostream>
#include <boost/type_traits/has_dereference.hpp>
struct A {
    A(int i) : x(i) {}
    int x;
template<typename T>
struct B {
    template<typename std::enable_if_t<!boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t.x;
    template<typename std::enable_if_t<boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t->x;
int main()
    A a{4};
    B<A> g;
    std::cout << g.getX(a) << std::endl;
    return 0;

But, this works fine.

struct B {
    template<typename T, typename std::enable_if_t<!boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t.x;
    template<typename T, typename std::enable_if_t<boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t->x;

Solution

This seems to work:

template<typename T1>
struct B {
    template<typename T = T1, typename std::enable_if_t<!boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t.x;
    template<typename T = T1, typename std::enable_if_t<boost::has_dereference<T>::value> * = nullptr>
    auto getX(T t) {
        return t->x;
                Looks like a duplicate. But stack overflow wasn't suggesting that thread to me. Thank you.
– Mochan
                May 13, 2019 at 17:42
                No problem, I knew what to search for because I answered the first duplicate I linked to :)
– Praetorian
                May 13, 2019 at 17:50