samedi 18 août 2018

Why does gcc tell me that my template is not a template

I have such a peace of code:

  template<template<typename> class ContainerType, typename ValueType, typename ReturnType> struct value_extractor {
  public:
    static ReturnType extract(const ContainerType<ValueType>&);
  };

  template<template<typename> class ContainerType, typename ValueType> struct value_extractor<ContainerType, ValueType, std::shared_ptr<ValueType>> {
    static std::shared_ptr<ValueType> extract(const ContainerType<ValueType>& value) {
      return value;
    }
  };

which essentially extracts value from a template type. This code compiles well using clang but with gcc I get an error saying:

g++ test.cpp -lstdc++ -O2 
In file included from di.hpp:1:0,
                 from test.cpp:2:
holders.hpp: In instantiation of ‘ReturnType di::holder<ContainerType, ValueType>::provide() const [with ReturnType = std::shared_ptr<int>; ContainerType = std::shared_ptr; ValueType = int]’:
di.hpp:35:105:   required from ‘static ReturnType di::holder_selector::convert(const types_map&, ContainerType<ValueType>*) [with ReturnType = std::shared_ptr<int>; ContainerType = std::shared_ptr; ValueType = int; di::types_map = std::unordered_map<void (*)(), std::unique_ptr<di::base_holder> >]’
di.hpp:40:39:   required from ‘T di::injector::provide() const [with T = std::shared_ptr<int>]’
test.cpp:14:63:   required from here
holders.hpp:48:85: error: ‘di::value_extractor<ContainerType, ValueType, std::shared_ptr<_Up> >::extract(const ContainerType<ValueType>&) [with ContainerType = std::shared_ptr; ValueType = int]’ is not a template [-fpermissive]
 alue_extractor<ContainerType, ValueType, ReturnType>::template extract(value_);
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~

If I use -fpermissive flag code compiles and even works but obviously emits a warning. So my question is: is it really me or this is gcc's error and if it's me writing nonconforming code then how should I fix it? Thnks in advance.

Aucun commentaire:

Enregistrer un commentaire