Recently I read some code about websocketpp, and the following code is what I'm confused about:
#include <somefile.hpp>
template <typename config>
class endpoint : public config::socket_type { //--------A--------//
typedef typename config::concurrency_type concurrency_type;//-----B------//
....
}
In the somefile.hpp, there is namespace which also called config. So I don't know whether the name "config" in A and B denoted the that namespace or the template parameter. I guess it is template parameter.
Thx for all people asking my questions.
The name of the template parameter is introduced in the scope of the primary template declaration. It hides the name of the namespace.
From the C++ 17 Standard (6.3.2 Point of declaration)
11 The point of declaration for a template parameter is immediately after its complete template-parameter
With a requires clause the template declaration could look more clear.
Here is a demonstrative program
namespace config
{
}
template <typename config> requires requires { typename config::socket_type; }
class endpoint : public config::socket_type
{
};
struct A
{
struct socket_type {};
};
int main()
{
endpoint<A> e;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With