• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Louis Dionne 2013-2017
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>
12 namespace hana = boost::hana;
13 
14 
15 //
16 // Make sure that http://stackoverflow.com/q/32702383/627587 works.
17 //
18 
__anon6f439f5b0102(auto& map, auto key) 19 auto at = [](auto& map, auto key) -> auto& {
20     return map[key];
21 };
22 
23 template <typename Map, typename Keys>
traverse(Map & map,Keys const & keys)24 auto& traverse(Map& map, Keys const& keys){
25     return hana::fold_left(keys, map, at);
26 }
27 
main()28 int 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 }
39