File: tuple_traits.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (89 lines) | stat: -rw-r--r-- 3,609 bytes parent folder | download | duplicates (13)
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
/*=============================================================================
    Copyright (c) 2016 Lee Clagett

    Distributed under 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/detail/lightweight_test.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/tuple/tuple.hpp>
#include <boost/config.hpp>
#include <boost/type_traits/is_constructible.hpp>
#include <boost/type_traits/is_convertible.hpp>

#define FUSION_SEQUENCE boost::fusion::tuple
#define FUSION_ALT_SEQUENCE boost::fusion::vector
#include "traits.hpp"

struct not_convertible {};

/*  Some construction differences in fusion::tuple from std::tuple:
      - Construction from elements cannot call an explicit constructor.
      - There is no implicit construction from elements.
      - Construction from std::pair is _enabled_ when tuple is not of size 2.
      - Construction from tuple is _enabled_ when destination tuple is of
        different size.
      - Implicit construction from std::pair can call explicit constructors on
        elements.
      - Implicit construction from tuple can call explicit constructors on
        elements.

    These differences are historical. Matching the behavior of std::tuple
    could break existing code, however, switching to fusion::vector would
    restore the historical behavior. */
int
main()
{
    using namespace boost::fusion;

    test_convertible(false /* no conversion construction */ );

    BOOST_TEST((is_convertible<std::pair<int, int>, tuple<int, int> >(true)));
    BOOST_TEST((
        is_convertible<std::pair<int, int>, tuple<convertible, int> >(true)
    ));
    BOOST_TEST((
        is_convertible<std::pair<int, int>, tuple<int, convertible> >(true)
    ));
    BOOST_TEST((
        is_convertible<
            std::pair<int, int>, tuple<convertible, convertible>
        >(true)
    ));

#if defined(FUSION_TEST_HAS_CONSTRUCTIBLE)
    test_constructible();

    BOOST_TEST((is_constructible< tuple<> >(true)));
    BOOST_TEST((is_constructible<tuple<>, int>(false)));

    BOOST_TEST((is_constructible< tuple<int> >(true)));
    BOOST_TEST((is_constructible<tuple<int>, int>(true)));
    BOOST_TEST((is_constructible<tuple<convertible>, int>(true)));
    BOOST_TEST((is_constructible<tuple<not_convertible>, int>(false)));
    BOOST_TEST((is_constructible< tuple<int>, vector<int> >(false)));
    BOOST_TEST((is_constructible<tuple<int>, int, int>(false)));

    BOOST_TEST((is_constructible< tuple<int, int> >(true)));
    // boost::is_constructible always fail to test ctor which takes 2 or more arguments on GCC 4.7.
#if !BOOST_WORKAROUND(BOOST_GCC, < 40700)
    BOOST_TEST((is_constructible<tuple<int, int>, int, int>(true)));
    BOOST_TEST((
        is_constructible<tuple<convertible, convertible>, int, int>(true)
    ));
#endif // !(gcc < 4.7)
    BOOST_TEST((is_constructible<tuple<int, not_convertible>, int, int>(false)));
    BOOST_TEST((is_constructible<tuple<not_convertible, int>, int, int>(false)));
    BOOST_TEST((
        is_constructible<tuple<not_convertible, not_convertible>, int, int>(false)
    ));
#if defined(BOOST_FUSION_HAS_VARIADIC_VECTOR)
    // C++03 fusion::tuple has constructors that can never be used
    BOOST_TEST((is_constructible<tuple<int, int>, int>(false)));
#endif
    BOOST_TEST((is_constructible<tuple<int, int>, int, int, int>(false)));

#endif // FUSION_TEST_HAS_CONSTRUCTIBLE

    return boost::report_errors();
}