Blame view

3rdparty/boost_1_81_0/libs/metaparse/doc/metafunction.qbk 1.27 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  [#metafunction]
  [section Template metafunction]
  
  A ['template metafunction] represents a function over types that is evaluated at
  compile-time. It is implemented by a template class.
  
  The template arguments of that class are expected to be types (`class` or
  `typename` template arguments). They represent the arguments of the
  metafunction.
  
  Instances of the template class are expected to have a public nested type called
  `type`. This type is the type the metafunction returns.
  
  Template metafunction are expected to be called with
  [link metaprogramming_value template metaprogramming values] as arguments only.
  
  Template metafunctions are expected to return template metaprogramming values.
  
  For example this is the identity template metafunction:
  
    template <class T>
    struct identity
    {
      using type = T;
    };
  
  This metafunction is called `identity`. It takes one argument, `T`. The result
  of calling this metafunction is its argument, `T`.
  
  To call this metafunction, one has to instantiate the template class. The
  template arguments it is instantiated with are the arguments the metafunction is
  called with. For example:
  
    identity<std::integral_constant<int, 13>>::type
  
  The above example calls the metafunction `identity` with
  `std::integral_constant<int, 13>` as its argument.
  
  [endsect]