2

I'm trying to hook an existing namespace onto std functionality by "using" some specific std math functions. The problem is that for coverage reasons i'd like to explicitly instantiate the template functions before i actually use them anywhere. Afterwards i want to write some unit tests that verify the functionality.

Example

namespace foo {
    using std::sin;
    // ...
}

This works fine, such that i can write

foo::sin(0);    

but, the explicit template instantiation doesn't work

template double foo::sin<int>(int); // doesn't work (this is what i want)

If i instantiate std::sin directly, it works.

template double std::sin<int>(int); // works

Can this this kind of reusing of namespace functionality be achieved for explicit template instantiations?

Edit

Someone marked this question as answered here, but this post seems to have a different problem. I do NOT want to define a specialization of a function template (std namespace to my own that is). Rather, i want my namespace to "imitate" the std namespace for some math functions.

Edit 2

I'm using clang 9 which throws an error. GCC happily compiles the code. (see comments below)

mtosch
  • 351
  • 4
  • 18
  • What happens when you use `template double foo::sin(int);`? Does it fail to compile? Does it fail to actually generate the specialization? – François Andrieux Sep 28 '20 at 18:34
  • error: explicit instantiation of 'sin' does not refer to a function template, variable template, member function, member class, or static data member template double foo::sin(int); – mtosch Sep 29 '20 at 15:05
  • It seems like [it works for me](https://godbolt.org/z/6Pq5eG). How are you compiling your code? Or did I misunderstand the question? – François Andrieux Sep 29 '20 at 15:58
  • Interesting. GCC compiles. I'm using clang 9.0.0 and get the error i mentioned above. A lot of posts online about namespaces and gcc vs. clang. For me it's still not clear how i can achieve what i want though.. – mtosch Sep 30 '20 at 15:10

0 Answers0