File: test_is_empty.cxx

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (93 lines) | stat: -rw-r--r-- 2,699 bytes parent folder | download | duplicates (11)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

//  (C) Copyright Edward Diener 2011-2015,2019
//  Use, modification and distribution are subject to the Boost Software License,
//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt).

#include <boost/vmd/is_empty.hpp>
#include <boost/preprocessor/facilities/empty.hpp>
#include <boost/preprocessor/variadic/has_opt.hpp>
#include <boost/detail/lightweight_test.hpp>

int main()
  {
  
#if BOOST_PP_VARIADICS

  #define DATA
  #define OBJECT OBJECT2
  #define OBJECT2
  #define FUNC(x) FUNC2(x)
  #define FUNC2(x)
  
  BOOST_TEST(BOOST_VMD_IS_EMPTY(BOOST_PP_EMPTY()));
  BOOST_TEST(BOOST_VMD_IS_EMPTY(DATA BOOST_PP_EMPTY()));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(x BOOST_PP_EMPTY()));
  BOOST_TEST(BOOST_VMD_IS_EMPTY(OBJECT BOOST_PP_EMPTY()));
  BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC(z) BOOST_PP_EMPTY()));
  
  #define FUNC_GEN() ()
  #define FUNC_GEN2(x) ()
  #define FUNC_GEN3() anything
  #define FUNC_GEN4(x) anything
  
#if BOOST_PP_VARIADIC_HAS_OPT()

  #define FUNC_GEN5(x,y) ()
  #define FUNC_GEN6(x,y) anything
  #define FUNC_GEN7() (y,z)
  #define FUNC_GEN5A() (&)
  #define FUNC_GEN6A(x) (y)
  #define FUNC_GEN7A() (y,z)
  
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN2));
  
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7));

  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5A));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6A));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7A));
  
#elif BOOST_VMD_MSVC

  #define FUNC_GEN5(x,y) ()
  #define FUNC_GEN6(x,y) anything
  
  /* This shows that VC++ does not work correctly in these cases. */

  BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN));  /* This produces the wrong result */
  BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN2)); /* This produces the wrong result */
  
  BOOST_TEST(BOOST_VMD_IS_EMPTY(FUNC_GEN5));  /* This should produce a compiler error but does not and produces the incorrect result */
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6)); /* This should produce a compiler error but does not */

#else

  #define FUNC_GEN5() (&)
  #define FUNC_GEN6(x) (y)
  #define FUNC_GEN7() (y,z)
  
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN2));
  
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN5));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN6));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN7));
  
#endif /* BOOST_VMD_MSVC */

  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN3));
  BOOST_TEST(!BOOST_VMD_IS_EMPTY(FUNC_GEN4));
  
#else

BOOST_ERROR("No variadic macro support");
  
#endif /* BOOST_PP_VARIADICS */

  return boost::report_errors();
  
  }