File: algorithm.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: 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 (108 lines) | stat: -rw-r--r-- 3,003 bytes parent folder | download | duplicates (3)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Boost.Geometry

// Copyright (c) 2021-2023, Oracle and/or its affiliates.

// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html


#include <geometry_test_common.hpp>

#include <boost/geometry/algorithms/assign.hpp>

#include <boost/geometry/arithmetic/arithmetic.hpp>

#include <boost/geometry/core/cs.hpp>

#include <boost/geometry/geometries/point.hpp>

#include <boost/geometry/util/algorithm.hpp>


void test_dimension(bg::util::index_constant<0>)
{
    bool called = false;
    bg::detail::for_each_index<0>([&](auto) { called = true; });
    BOOST_CHECK(!called);
    BOOST_CHECK(bg::detail::all_indexes_of<0>([&](auto) { return true; }) == true);
    BOOST_CHECK(bg::detail::all_indexes_of<0>([&](auto) { return false; }) == true);
    BOOST_CHECK(bg::detail::any_index_of<0>([&](auto) { return true; }) == false);
    BOOST_CHECK(bg::detail::any_index_of<0>([&](auto) { return false; }) == false);
    BOOST_CHECK(bg::detail::none_index_of<0>([&](auto) { return true; }) == true);
    BOOST_CHECK(bg::detail::none_index_of<0>([&](auto) { return false; }) == true);
}

template <std::size_t I>
void test_dimension(bg::util::index_constant<I>)
{
    using point = bg::model::point<double, I, bg::cs::cartesian>;
    point p;
    bg::assign_value(p, 10.0);

    bg::detail::for_each_index<I>([&](auto index)
    {
        BOOST_CHECK(bg::get<index>(p) == 10.0);
        bg::set<index>(p, double(index));
    });
    bg::detail::for_each_dimension<point>([&](auto index)
    {
        BOOST_CHECK(bg::get<index>(p) == double(index));
    });

    BOOST_CHECK(
        bg::detail::all_indexes_of<0>([&](auto index)
        {
            return bg::get<index>(p) == double(index);
        }) == true);
    BOOST_CHECK(
        bg::detail::all_dimensions_of<point>([&](auto index)
        {
            return bg::get<index>(p) == 10;
        }) == false);
    BOOST_CHECK(
        bg::detail::any_index_of<0>([&](auto)
        {
            return false;
        }) == false);
    BOOST_CHECK(
        bg::detail::any_dimension_of<point>([&](auto index)
        {
            return bg::get<index>(p) == double(I - 1);
        }) == true);
    BOOST_CHECK(
        bg::detail::none_index_of<0>([&](auto)
        {
            return false;
        }) == true);
    BOOST_CHECK(
        bg::detail::none_dimension_of<point>([&](auto index)
        {
            return bg::get<index>(p) == double(0);
        }) == false);
}

template <std::size_t I, std::size_t N>
struct test_dimensions
{
    static void apply()
    {
        test_dimension(bg::util::index_constant<I>());
        test_dimensions<I + 1, N>::apply();
    }
};

template <std::size_t N>
struct test_dimensions<N, N>
{
    static void apply() {}
};

int test_main(int, char* [])
{
    test_dimensions<0, 5>::apply();

    return 0;
}