Blame view

3rdparty/boost_1_81_0/libs/metaparse/doc/alphanum.qbk 1.24 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  [#alphanum]
  [section alphanum]
  
  [h1 Synopsis]
  
    struct alphanum;
  
  This is a [link parser parser].
  
  [h1 Description]
  
  It accepts one character in the range `a-z`, `A-Z` or `0-9`. The
  result of the parser is the accepted character.
  
  [h1 Header]
  
    #include <boost/metaparse/alphanum.hpp>
  
  [h1 Expression semantics]
  
  The following are equivalent:
  
    alphanum
    
    one_of<digit, letter>
  
  [h1 Example]
  
    #include <boost/metaparse/alphanum.hpp>
    #include <boost/metaparse/start.hpp>
    #include <boost/metaparse/string.hpp>
    #include <boost/metaparse/is_error.hpp>
    #include <boost/metaparse/get_result.hpp>
    
    using namespace boost::metaparse;
    
    static_assert(
      !is_error<alphanum::apply<BOOST_METAPARSE_STRING("0"), start>>::type::value,
      "alphanum should accept a digit"
    );
    
    static_assert(
      !is_error<alphanum::apply<BOOST_METAPARSE_STRING("x"), start>>::type::value,
      "alphanum should accept a character"
    );
    
    static_assert(
      get_result<
        alphanum::apply<BOOST_METAPARSE_STRING("x"), start>
      >::type::value == 'x',
      "the result of parsing should be the character value"
    );
    
    static_assert(
      is_error<alphanum::apply<BOOST_METAPARSE_STRING(","), start>>::type::value,
      "alphanum should reject a comma"
    );
  
  [endsect]