1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // QuickBook Example
3
4 // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <boost/config.hpp>
11 #ifdef BOOST_NO_CXX11_HDR_ARRAY
12
main()13 int main()
14 {
15 return 0;
16 }
17
18 #else //this example needs C++11 std::array
19
20 //[std_array
21 //` Shows how to use a C++11 std::array using Boost.Geometry's distance, set and assign_values algorithms
22
23 #include <iostream>
24
25 #include <boost/geometry.hpp>
26 #include <boost/geometry/geometries/linestring.hpp>
27 #include <boost/geometry/geometries/adapted/std_array.hpp>
28
BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(cs::cartesian)29 BOOST_GEOMETRY_REGISTER_STD_ARRAY_CS(cs::cartesian)
30
31 int main()
32 {
33 std::array<float, 2> a = { {1, 2} };
34 std::array<double, 2> b = { {2, 3} };
35 std::cout << boost::geometry::distance(a, b) << std::endl;
36
37 boost::geometry::set<0>(a, 1.1f);
38 boost::geometry::set<1>(a, 2.2f);
39 std::cout << boost::geometry::distance(a, b) << std::endl;
40
41 boost::geometry::assign_values(b, 2.2, 3.3);
42 std::cout << boost::geometry::distance(a, b) << std::endl;
43
44 boost::geometry::model::linestring<std::array<double, 2> > line;
45 line.push_back(b);
46
47 return 0;
48 }
49
50 //]
51
52 #endif //BOOST_NO_CXX11_HDR_ARRAY
53
54 //[std_array_output
55 /*`
56 Output:
57 [pre
58 1.41421
59 1.20416
60 1.55563
61 ]
62 */
63 //]
64