]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/map/at_key.stackoverflow.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / map / at_key.stackoverflow.cpp
CommitLineData
b32b8144 1// Copyright Louis Dionne 2013-2017
7c673cae
FG
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5#include <boost/hana/assert.hpp>
6#include <boost/hana/at_key.hpp>
7#include <boost/hana/fold_left.hpp>
8#include <boost/hana/integral_constant.hpp>
9#include <boost/hana/map.hpp>
10#include <boost/hana/pair.hpp>
11#include <boost/hana/range.hpp>
12namespace hana = boost::hana;
13
14
15//
16// Make sure that http://stackoverflow.com/q/32702383/627587 works.
17//
18
19auto at = [](auto& map, auto key) -> auto& {
20 return map[key];
21};
22
23template <typename Map, typename Keys>
24auto& traverse(Map& map, Keys const& keys){
25 return hana::fold_left(keys, map, at);
26}
27
28int main() {
29 auto xs = hana::make_map(hana::make_pair(hana::int_c<0>,
30 hana::make_map(hana::make_pair(hana::int_c<1>,
31 hana::make_map(hana::make_pair(hana::int_c<2>,
32 hana::make_map(hana::make_pair(hana::int_c<3>, 10))))))));
33
34 int& i = traverse(xs, hana::range_c<int, 0, 4>);
35 BOOST_HANA_RUNTIME_CHECK(i == 10);
36 i = 99;
37 BOOST_HANA_RUNTIME_CHECK(traverse(xs, hana::range_c<int, 0, 4>) == 99);
38}