簡體   English   中英

C ++ Boost模板類型和非類型

[英]c++ boost template type and non-type

template <class Target>
struct unwrap_predicate<void (Target)>
{
    typedef is_convertible<mpl::_, Target> type;
};

這是Boost庫中整個程序的一段代碼,請參見: http : //www.boost.org/doc/libs/release/boost/parameter/preprocessor.hpp

我不了解目標。 類旁邊的第一個目標。 這是一個類型參數。 第二個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
}

這是一個函數類型。

void (Target)

是返回void(即不返回任何值)並采用Target類型的單個參數的函數的類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM