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/equal.hpp> 7 #include <boost/hana/fold_left.hpp> 8 #include <boost/hana/integral_constant.hpp> 9 #include <boost/hana/plus.hpp> 10 #include <boost/hana/string.hpp> 11 #include <boost/hana/value.hpp> 12 namespace hana = boost::hana; 13 14 main()15int main() { 16 auto sum_string = [](auto str) { 17 return hana::fold_left(str, hana::int_c<0>, [](auto sum, auto c) { 18 constexpr int i = hana::value(c) - 48; // convert character to decimal 19 return sum + hana::int_c<i>; 20 }); 21 }; 22 23 BOOST_HANA_CONSTANT_CHECK( 24 sum_string(BOOST_HANA_STRING("1234")) == hana::int_c<1 + 2 + 3 + 4> 25 ); 26 } 27