0

I shrunk down the problem to this:

template <typename value_t, bool citrus = false> struct fruit_structs {
    struct fruit_base { value_t weight; };
    struct banana_t : fruit_base {};
    struct lemon_t : fruit_base {};

    using fruit_t = typename std::conditional<citrus, lemon_t, banana_t>::type;
};

template<typename value_t> using banana_struct = fruit_structs<value_t, false>::fruit_t;
template<typename value_t> using lemon_struct = fruit_structs<value_t, true>::fruit_t;

In reality, banana_t and lemon_t share a lot of logic and value_t specific utilities so my options as I saw them were either a horrificly redundant template specialization or this. Problem with this is that it doesn't work, hence the post.

Intellisence claims "syntax error: identifier 'fruit_t'" on the last lines where I try to alias. Why is that?

user81993
  • 6,167
  • 6
  • 32
  • 64

1 Answers1

1

You compiler can't be sure that what you're referencing is a type. Make it explicit by prepending the typename keyword:

template<typename value_t> using banana_struct = typename fruit_structs<value_t, false>::fruit_t;

template<typename value_t> using lemon_struct = typename fruit_structs<value_t, true>::fruit_t;
cigien
  • 57,834
  • 11
  • 73
  • 112
MorningDewd
  • 501
  • 2
  • 6