1 // The Art of C++ / Sequences 2 // Copyright (c) 2015 Daniel Frey 3 4 #ifndef TAOCPP_SEQUENCES_INCLUDE_PARTIAL_SUM_HPP 5 #define TAOCPP_SEQUENCES_INCLUDE_PARTIAL_SUM_HPP 6 7 #include <cstddef> 8 #include <utility> 9 10 #include "make_integer_sequence.hpp" 11 #include "sum.hpp" 12 13 namespace tao 14 { 15 namespace seq 16 { 17 namespace impl 18 { 19 template< std::size_t, typename S, typename = make_index_sequence< S::size() > > 20 struct partial_sum; 21 22 template< std::size_t I, typename T, T... Ns, std::size_t... Is > 23 struct partial_sum< I, integer_sequence< T, Ns... >, index_sequence< Is... > > 24 : seq::sum< T, ( ( Is < I ) ? Ns : 0 )... > 25 { 26 static_assert( I <= sizeof...( Is ), "tao::seq::partial_sum<I, S>: I is out of range" ); 27 }; 28 } 29 30 template< std::size_t I, typename T, T... Ns > 31 struct partial_sum 32 : impl::partial_sum< I, integer_sequence< T, Ns... > > 33 {}; 34 35 template< std::size_t I, typename T, T... Ns > 36 struct partial_sum< I, integer_sequence< T, Ns... > > 37 : impl::partial_sum< I, integer_sequence< T, Ns... > > 38 {}; 39 } 40 } 41 42 #endif // TAOCPP_SEQUENCES_INCLUDE_PARTIAL_SUM_HPP 43