Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
48 Views

Variadic constructor with enable_if not found? (C++11)

I'm having a bit of trouble with the following C++11 code fragment and icpc 15.0.0. This example is compiled correctly by g++ 4.9. I essentially have a templated vector class (with its scalar type T and size N being template arguments).

The variadically templated constructor that checks whether all the arguments are assignable to T& is not found. When I remove the assignable check (which I cannot do because otherwise an ambiguity occurs with the copy-constructor when N=1) the example compiles.

The manually expanded version for 2 arguments compiles. Any idea for a work-around.

// > icpc -v
// icpc version 15.0.0 (gcc version 4.9.0 compatibility)

// > icpc -std=c++11 i_dont_know_what_is_wrong_with_intel.cpp
// i_dont_know_what_is_wrong_with_intel.cpp(39): error: no instance of constructor "Dummy<T, N>::Dummy [with T=double, N=2U]" matches the argument list
//             argument types are: (double, double)
//     Dummy<double, 2> t{1.0, 2.0};
//                       ^
// compilation aborted for i_dont_know_what_is_wrong_with_intel.cpp (code 2)

#include <type_traits>

template<typename ...T>
struct All : std::true_type { };

template<typename Head, typename ...Tail>
struct All<Head, Tail ...> : std::conditional<Head::value, All<Tail ...>, std::false_type>::type { };

template<typename T, unsigned N>
struct Dummy
{
  // this should work (and does in g++ 4.9), but doesn't
  template<typename ...Args, class = typename std::enable_if</*sizeof...(Args) == N && */
    All<
      std::is_assignable<T&, Args> ...
    >::value
  >::type>
  explicit Dummy(const Args &...args)
  {
  }
};

// this works
template<typename T>
struct DummyFixed2
{
  template<typename Arg1, typename Arg2, class = typename std::enable_if<
    All<
      std::is_assignable<T&, Arg1>,
      std::is_assignable<T&, Arg2>,
    >::value
  >::type>
  explicit DummyFixed2(const Arg1 &arg1, const Arg2 &arg2)
  {
  }
};

int main(int argc, char const *argv[])
{
  DummyFixed2<double> f{1.0, 2.0};
  Dummy<double, 2> t{1.0, 2.0};
  /* code */
  return 0;
}

 

0 Kudos
5 Replies
Highlighted
Beginner
48 Views

Version 15.0.2 exhibits the same problem. I'm really stumped for a work-around... :(

0 Kudos
Highlighted
Employee
48 Views

Hi Daniel,
I've filed this issue with the developers and will get back to you as soon as I've an update. Appreciate your patience till then. 
_Kittur

0 Kudos
Highlighted
Beginner
48 Views

verifique um provável upgrade para a Version 15.0.2 ou superior, com certeza vai resolver seu problema sem precisar codificar as regras que já existe. 

0 Kudos
Highlighted
Employee
48 Views

HI Cardin! 
I've to find someone who can decipher your response! Thanks for the response and hopefully I should find out more on that.
BTW, this issue fails with ICC (with GNU >=4.7 which accepts) and is a bug that I've filed with the developers as mentioned earlier.

_Kittur

0 Kudos
Highlighted
Beginner
48 Views

Hi,

This problem still exists with Intel 17.1 but works with GCC 6.2 and Clang 3.9.0. Is this going to be resolved soon?

 

Best,

Nils

0 Kudos