Reputation: 920
This is a simple question in fact. I have a template class with one parameter. In an other object, I make it a friend of it, like this :
template< typename type_t >
class A
{
...
}
template< typename type_t >
class B
{
template< typename >
friend class A; // Works fine !
...
}
After that, I wanted to add a condition to discard integral number when instancing the class A (and B by the way), by doing this :
template< typename type_t, std::enable_if_t< std::is_floating_point_v< type_t >, bool > = false >
class A
{
...
}
template< typename type_t, std::enable_if_t< std::is_floating_point_v< type_t >, bool > = false >
class B
{
template< typename >
friend class A; // ============> Error!
...
}
By reading the compiler message, I understood the template now has two parameters. But what should I put to the second parameter when I'm friending the class ? I tried template< typename, typename >, template< typename, bool > and template< typename, true >... All fails to compile.
What is the solution here ?
Upvotes: 2
Views: 290
Reputation: 41820
As StoryTeller said in the comments, a static_assert
inside the class B
or A
might be a simpler solution. It will not use a second template parameter and will enable the familiar friend declaration.
However, if you still want to go through the SFINAE way, you can declare your friend using the full SFINAE expression in it:
template<typename type_t, std::enable_if_t<std::is_floating_point_v<type_t>, bool> = false>
class B
{
template<typename T, std::enable_if_t<std::is_floating_point_v<T>, bool>>
friend class A;
};
Upvotes: 3