cpp*_*hon 0 c++ templates boost
template <class Target>
struct unwrap_predicate<void (Target)>
{
typedef is_convertible<mpl::_, Target> type;
};
Run Code Online (Sandbox Code Playgroud)
这是来自Boost库的整个程序的一段代码,请参阅:http://www.boost.org/doc/libs/release/boost/parameter/preprocessor.hpp
我不明白Target.Class旁边的第一个Target.这是一个类型参数.第二个void(Target)看起来像我的非类型参数.一个参数如何作为类型和非类型.我对这两行感到困惑.有人可以帮忙吗?
第二个void(Target)看起来像我的非类型参数.
它不是,Target只是这里类型的一部分 - 一个返回void的函数类型.
你有什么是一个部分模板专业化的任何函数类型,它接受一个参数并返回void.
例:
template <typename T>
struct unwrap { static const int i = 0; };
template<typename T>
struct unwrap<void(T)> { static const int i = 1; };
void foo(int&);
int main()
{
unwrap<int> u1;
unwrap<decltype(foo)> u2;
std::cout << u1.i << u2.i; // prints 01
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
117 次 |
| 最近记录: |