File: array_c_array_test.cpp

package info (click to toggle)
boost1.90 1.90.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 593,168 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,162; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (71 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download | duplicates (4)
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
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#define BOOST_ALLOW_DEPRECATED_SYMBOLS

#include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <cstddef>

// c_array and get_c_array are deprecated nonstandard extensions

template<class T, std::size_t N> void test()
{
    boost::array<T, N> a = {};

    T* p1 = a.c_array();
    T* p2 = a.data();

    BOOST_TEST_EQ( p1, p2 );
}

template<class T, std::size_t N> void test2()
{
    {
        boost::array<T, N> a = {{}};

        T (&e1)[ N ] = boost::get_c_array( a );
        T (&e2)[ N ] = a.elems;

        BOOST_TEST_EQ( static_cast<T*>( e1 ), static_cast<T*>( e2 ) );
    }
    {
        boost::array<T, N> const a = {{}};

        T const (&e1)[ N ] = boost::get_c_array( a );
        T const (&e2)[ N ] = a.elems;

        BOOST_TEST_EQ( static_cast<T const*>( e1 ), static_cast<T const*>( e2 ) );
    }
}

int main()
{
    test<int, 0>();
    test<int, 1>();
    test<int, 7>();

    test<int const, 0>();

#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) || BOOST_WORKAROUND(BOOST_GCC, < 50000)

    // = {} doesn't work for const T

#else

    test<int const, 1>();
    test<int const, 7>();

#endif

    test2<int, 1>();
    test2<int, 7>();

    test2<int const, 1>();
    test2<int const, 7>();

    return boost::report_errors();
}