Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Syntax error on recursive and nested template argument deduction.(Eclpse marks as syntax error a compilable and executable code that implements a recursive and nested template argument deduction.)
Syntax error on recursive and nested template argument deduction. [message #1775369] Sat, 28 October 2017 13:32
Alvaro Cortes is currently offline Alvaro CortesFriend
Messages: 1
Registered: October 2017
Junior Member
Hi everyone.

I have a variadic template "function" called test<T1, T2, ..., Tn> returning bool that works as follows:

1. If n > 1, then test returns true if test<T1> || test<T2> || ... || test<Tn> is true.
2. If n == 1, then test returns true if :
2.1. If T1 is not a template type, returns true if T1 is an integer (that is std::is_same<Ti,int>::value == true).
2.2. If T1 is a template of type U<U1,U2,...,Um> then returns true if test<U1> || test<U2> || ... || test<Um> is true.

The better way I found to implement this is the following code:

#include <type_traits>
#include <vector>

// Case 1 in the case of having T1 as non-template type.
template <typename T, typename... Args>   struct has_int {
        static constexpr bool check() {  return std::is_same<T,int>::value || has_int<Args...>::check();   }
        static const constexpr bool value = check();
};

// Case 2.1
template<typename T> struct has_int<T>  {
        static constexpr bool check()  { return std::is_same<T,int>::value;  }
        static const constexpr bool value = check();
};

// Case 1 in the case of having T1 as template type
template <template<typename...> class X, typename... XArgs, typename... Args>  struct has_int<X<XArgs...>,Args...>  {
       static constexpr bool check()  {  return has_int<XArgs...>::value || has_int<Args...>::value;   }
       static const constexpr bool value  = check();
};

// Case 2.2
template <template<typename...> class X, typename... XArgs> struct has_int<X<XArgs...>>  {
       static constexpr bool check() {  return has_int<XArgs...>::value;  }
       static const constexpr bool value  = check();
 };

int main() {
  printf("%d\n", has_int<std::vector<int>>::value);     // <- Eclipse syntax error (Symbol 'value' could not be resolved),
                     // but it is compilable, executable and works fine printing 1.
  return 0;
}



I'm using Eclipse Photon and I have enabled c++11 flag on CDT GCC Builtin Compiler Settings. I have tested that this problem is present also in Eclipse neon and Eclipse Oxygen.
Is it necessary to configure Eclipse in some other form to remove this error message?

Thanks in advance.
Previous Topic:Missing release notes
Next Topic:Parallel Build not working when is limited
Goto Forum:
  


Current Time: Sat Dec 16 20:40:32 GMT 2017

Powered by FUDForum. Page generated in 0.01829 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software