cristi1990an / Tensor-plus-plus

tensor_lib::tensor is a class template that describes a mathematical tensor, implemented as a heap allocated array. It is build as an alternative to structures such as std::vector <std::vector <std::vector<...>>>, replicating its behaviour and syntax almost entirely with the added benefits of having its data contiguous in memory.
1 stars 3 forks source link

Non conformant code (following the thread on reddit) #2

Closed FederAndInk closed 3 years ago

FederAndInk commented 3 years ago

Hi, Nihili0 from reddit here

Just to let you know before you hit cryptic compiler error

https://github.com/cristi1990an/Tensor-plus-plus/blob/5402c63f07e0fe6392913a06bf770404a7c4376c/tensor.hpp#L103

you can't specialize functions on untemplated arguments

you can do:

struct S {
  template<typename T>
  void f(T const& t) {
  }

  template<>
  void f(int const& i) {
  }
};

but you can't do:

template<typename T>
struct S {
  template<typename U>
  void f(U const& u) {
  }

  template<>
  void f(int i) { // error: not a const&
  }

  template<std::size_t R>
  void f(useful_specializations::nested_initializer_list<T, R> const&) {
  }

  template <>
  constexpr void construct_order_array<1u>(const std::initializer_list<T>& data) { // error: not specializing on templated type
  }
};
cristi1990an commented 3 years ago

Fixed

În lun., 12 iul. 2021 la 22:41, Ludovic J @.***> a scris:

Hi, Nihili0 from reddit here

Just to let you know before you hit cryptic compiler error

https://github.com/cristi1990an/Tensor-plus-plus/blob/5402c63f07e0fe6392913a06bf770404a7c4376c/tensor.hpp#L103

you can't specialize functions on untemplated arguments

you can do:

struct S { template void f(T const& t) { }

template<> void f(int const& i) { } };

but you can't do:

templatestruct S { template void f(U const& u) { }

template<> void f(int i) { // error: not a const& }

template void f(useful_specializations::nested_initializer_list<T, R> const&) { }

template <> constexpr void construct_order_array<1u>(const std::initializer_list& data) { // error: not specializing on templated type } };

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cristi1990an/Tensor-plus-plus/issues/2, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFSQZMETRA5EKJPCPDXRBUDTXNANPANCNFSM5AHPU5YQ .