// // Copyright 2013 Francisco Jerez // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. // #ifndef CLOVER_UTIL_TUPLE_HPP #define CLOVER_UTIL_TUPLE_HPP #include namespace clover { namespace tuple { /// /// Static sequence of integers. /// template struct integral_sequence; /// /// Static sequence containing all integers from 0 to N-1. /// template struct enumerate { typedef typename enumerate::type type; }; template struct enumerate<0, Is...> { typedef integral_sequence type; }; namespace detail { template::type>::value >::type> struct _apply; template struct _apply> { typedef typename std::remove_reference::type func_type; typedef decltype( std::declval()(std::get(std::declval())...) ) value_type; static value_type eval(F &&f, T &&t) { return f(std::get(std::forward(t))...); } }; } /// /// Evaluate function \a f with the elements of tuple \a t /// expanded as arguments. /// template typename detail::_apply::value_type apply(F &&f, T &&t) { return detail::_apply::eval(std::forward(f), std::forward(t)); } namespace detail { template::type>::value >::type> struct _map; template struct _map> { typedef typename std::remove_reference::type func_type; typedef std::tuple< decltype(std::declval()( std::get(std::declval())))... > value_type; static value_type eval(F &&f, T &&t) { return value_type(f(std::get(std::forward(t)))...); } }; } /// /// Evaluate function \a f on each element of the tuple \a t and /// return the resulting values as a new tuple. /// template typename detail::_map::value_type map(F &&f, T &&t) { return detail::_map::eval(std::forward(f), std::forward(t)); } } } #endif