/*============================================================================= Copyright (c) 2011-2014 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprout Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #include #include #include #include #include #include #include // // hanoi // template< std::size_t N, typename Id, typename sprout::enabler_if<(N == 0)>::type = sprout::enabler > SPROUT_CONSTEXPR sprout::array, 0> hanoi(Id, Id, Id) { return sprout::array, 0>{{}}; } template< std::size_t N, typename Id, typename sprout::enabler_if<(N != 0)>::type = sprout::enabler > SPROUT_CONSTEXPR sprout::array, sprout::static_pow2m1::value> hanoi(Id a, Id b, Id c) { typedef sprout::tuple type; return sprout::append_back( sprout::push_back(hanoi(a, c, b), type(a, b, N)), hanoi(c, b, a) ); } #include int main() { constexpr auto answer = hanoi<8>('a', 'b', 'c'); for (auto const& e : answer) { std::cout << "disk " << sprout::get<2>(e) << ": " << sprout::get<0>(e) << " -> " << sprout::get<1>(e) << std::endl; } }