99#include " ../../core/eosio/serialize.hpp"
1010#include " ../../core/eosio/fixed_bytes.hpp"
1111
12+ #include < bluegrass/meta/for_each.hpp>
13+
1214#include < vector>
1315#include < tuple>
14- #include < boost/hana.hpp>
1516#include < functional>
1617#include < utility>
1718#include < type_traits>
@@ -303,8 +304,6 @@ struct secondary_key_traits<TYPE> {\
303304
304305namespace _multi_index_detail {
305306
306- namespace hana = boost::hana;
307-
308307 template <typename T>
309308 struct secondary_index_db_functions ;
310309
@@ -342,7 +341,7 @@ namespace _multi_index_detail {
342341 *
343342 * @ingroup multiindex
344343 * @tparam IndexName - is the name of the index. The name must be provided as an EOSIO base32 encoded 64-bit integer and must conform to the EOSIO naming requirements of a maximum of 13 characters, the first twelve from the lowercase characters a-z, digits 1-5, and ".", and if there is a 13th character, it is restricted to lowercase characters a-p and ".".
345- * @tparam Extractor - is a function call operator that takes a const reference to the table object type and returns either a secondary key type or a reference to a secondary key type. It is recommended to use the `eosio::const_mem_fun` template, which is a type alias to the `boost::multi_index::const_mem_fun`. See the documentation for the Boost `const_mem_fun` key extractor for more details .
344+ * @tparam Extractor - is a function call operator that takes a const reference to the table object type and returns either a secondary key type or a reference to a secondary key type. It is recommended to use the `eosio::const_mem_fun` template.
346345 *
347346 * Example:
348347 *
@@ -760,29 +759,34 @@ class multi_index
760759 template <uint64_t I>
761760 struct intc { enum e{ value = I }; operator uint64_t ()const { return I; } };
762761
763- static constexpr auto transform_indices ( ) {
764- using namespace _multi_index_detail ;
765-
766- typedef decltype ( hana::zip_shortest (
767- hana::make_tuple ( intc<0 >(), intc<1 >(), intc<2 >(), intc<3 >(), intc<4 >(), intc<5 >(),
768- intc<6 >(), intc<7 >(), intc<8 >(), intc<9 >(), intc<10 >(), intc<11 >(),
769- intc<12 >(), intc<13 >(), intc<14 >(), intc<15 >() ),
770- hana::tuple<Indices...>() ) ) indices_input_type;
771-
772- return hana::transform ( indices_input_type (), [&]( auto && idx ){
773- typedef typename std::decay<decltype (hana::at_c<0 >(idx))>::type num_type;
774- typedef typename std::decay<decltype (hana::at_c<1 >(idx))>::type idx_type;
775- return hana::make_tuple ( hana::type_c<index<eosio::name::raw (static_cast <uint64_t >(idx_type::index_name)),
776- typename idx_type::secondary_extractor_type,
777- num_type::e::value, false > >,
778- hana::type_c<index<eosio::name::raw (static_cast <uint64_t >(idx_type::index_name)),
779- typename idx_type::secondary_extractor_type,
780- num_type::e::value, true > > );
781-
782- });
783- }
762+ template <size_t Num, typename ... Values>
763+ class make_index_tuple {
764+ template <uint64_t ... Seq>
765+ static constexpr auto get_type (std::index_sequence<Seq...>) {
766+ return std::make_tuple (std::make_tuple (index<eosio::name::raw (static_cast <uint64_t >(Values::index_name)),
767+ typename Values::secondary_extractor_type,
768+ intc<Seq>::e::value, false >{},
769+ index<eosio::name::raw (static_cast <uint64_t >(Values::index_name)),
770+ typename Values::secondary_extractor_type,
771+ intc<Seq>::e::value, true >{})...);
772+ }
773+ public:
774+ using type = decltype ( get_type(std::make_index_sequence<Num>{}) );
775+ };
784776
785- typedef decltype ( multi_index::transform_indices() ) indices_type;
777+ using indices_type = typename make_index_tuple<sizeof ... (Indices), Indices...>::type;
778+
779+ class make_extractor_tuple {
780+ template <typename Obj, typename IndicesType, uint64_t ... Seq>
781+ static constexpr auto get_type (const IndicesType& indices, const Obj& obj, std::index_sequence<Seq...>) {
782+ return std::make_tuple (decltype (get<0 >(std::get<Seq>(indices)))::extract_secondary_key (obj)...);
783+ }
784+ public:
785+ template <typename Obj, typename IndicesType>
786+ static auto get_extractor_tuple (const IndicesType& indices, const Obj& obj) {
787+ return get_type (indices, obj, std::make_index_sequence<sizeof ...(Indices)>{});
788+ }
789+ };
786790
787791 indices_type _indices;
788792
@@ -810,9 +814,8 @@ class multi_index
810814 ds >> val;
811815
812816 i.__primary_itr = itr;
813- hana::for_each ( _indices, [&]( auto & idx ) {
814- typedef typename decltype (+hana::at_c<1 >(idx))::type index_type;
815-
817+ bluegrass::meta::for_each (_indices, [&](auto & idx){
818+ typedef decltype (std::get<1 >(idx)) index_type;
816819 i.__iters [ index_type::number () ] = -1 ;
817820 });
818821 });
@@ -850,7 +853,7 @@ class multi_index
850853 * - `Indices` is a list of up to 16 secondary indices.
851854 * - Each must be a default constructable class or struct
852855 * - Each must have a function call operator that takes a const reference to the table object type and returns either a secondary key type or a reference to a secondary key type
853- * - It is recommended to use the eosio::const_mem_fun template, which is a type alias to the boost::multi_index::const_mem_fun. See the documentation for the Boost const_mem_fun key extractor for more details.
856+ * - It is recommended to use the eosio::const_mem_fun template
854857 *
855858 * Example:
856859 *
@@ -1412,13 +1415,13 @@ class multi_index
14121415 auto get_index () {
14131416 using namespace _multi_index_detail ;
14141417
1415- auto res = hana::find_if ( _indices, []( auto && in ) {
1416- return std::integral_constant< bool , static_cast < uint64_t > (std::decay< typename decltype (+hana::at_c< 0 >(in ))::type>::type:: index_name) == static_cast <uint64_t >(IndexName)>( );
1417- });
1418+ constexpr uint64_t index_num = bluegrass::meta::for_each ( _indices, [&]( auto & idx) {
1419+ return decltype (std::get< 0 >(idx ))::index_name == static_cast <uint64_t >(IndexName);
1420+ }, _indices );
14181421
1419- static_assert ( res != hana::nothing , " name provided is not the name of any secondary index within multi_index" );
1422+ static_assert ( index_num < sizeof ...(Indices) , " name provided is not the name of any secondary index within multi_index" );
14201423
1421- return typename decltype (+hana::at_c <0 >(res. value ( ))):: type (this );
1424+ return decltype (std::get <0 >(std::get<index_num>(_indices )))(this );
14221425 }
14231426
14241427 /* *
@@ -1463,13 +1466,13 @@ class multi_index
14631466 auto get_index ()const {
14641467 using namespace _multi_index_detail ;
14651468
1466- auto res = hana::find_if ( _indices, []( auto && in ) {
1467- return std::integral_constant< bool , static_cast < uint64_t > (std::decay< typename decltype (+hana::at_c< 1 >(in ))::type>::type:: index_name) == static_cast <uint64_t >(IndexName)>( );
1468- });
1469+ constexpr uint64_t index_num = bluegrass::meta::for_each ( _indices, [&]( auto & idx) {
1470+ return decltype (std::get< 1 >(idx ))::index_name == static_cast <uint64_t >(IndexName);
1471+ }, _indices );
14691472
1470- static_assert ( res != hana::nothing , " name provided is not the name of any secondary index within multi_index" );
1473+ static_assert ( index_num < sizeof ...(Indices) , " name provided is not the name of any secondary index within multi_index" );
14711474
1472- return typename decltype (+hana::at_c <1 >(res. value ( ))):: type (this );
1475+ return decltype (std::get <1 >(std::get<index_num>(_indices )))(this );
14731476 }
14741477
14751478 /* *
@@ -1582,10 +1585,10 @@ class multi_index
15821585 if ( pk >= _next_primary_key )
15831586 _next_primary_key = (pk >= no_available_primary_key) ? no_available_primary_key : (pk + 1 );
15841587
1585- hana:: for_each ( _indices, [&]( auto & idx ) {
1586- typedef typename decltype (+hana::at_c <0 >(idx))::type index_type;
1588+ bluegrass::meta:: for_each (_indices, [&](auto & idx) {
1589+ typedef decltype (std::get <0 >(idx)) index_type;
15871590
1588- i.__iters [index_type::number ()] = secondary_index_db_functions<typename index_type::secondary_key_type>::db_idx_store ( _scope, index_type::name (), payer.value , obj.primary_key (), index_type::extract_secondary_key (obj) );
1591+ i.__iters [index_type::number ()] = secondary_index_db_functions<typename index_type::secondary_key_type>::db_idx_store ( _scope, index_type::name (), payer.value , obj.primary_key (), index_type::extract_secondary_key (obj) );
15891592 });
15901593 });
15911594
@@ -1695,11 +1698,7 @@ class multi_index
16951698 auto & mutableitem = const_cast <item&>(objitem);
16961699 eosio::check ( _code == current_receiver (), " cannot modify objects in table of another contract" ); // Quick fix for mutating db using multi_index that shouldn't allow mutation. Real fix can come in RC2.
16971700
1698- auto secondary_keys = hana::transform ( _indices, [&]( auto && idx ) {
1699- typedef typename decltype (+hana::at_c<0 >(idx))::type index_type;
1700-
1701- return index_type::extract_secondary_key ( obj );
1702- });
1701+ auto secondary_keys = make_extractor_tuple::get_extractor_tuple (_indices, obj);
17031702
17041703 auto pk = obj.primary_key ();
17051704
@@ -1724,11 +1723,10 @@ class multi_index
17241723 if ( pk >= _next_primary_key )
17251724 _next_primary_key = (pk >= no_available_primary_key) ? no_available_primary_key : (pk + 1 );
17261725
1727- hana::for_each ( _indices, [&]( auto & idx ) {
1728- typedef typename decltype (+hana::at_c<0 >(idx))::type index_type;
1729-
1726+ bluegrass::meta::for_each (_indices, [&](auto & idx){
1727+ typedef decltype (std::get<0 >(idx)) index_type;
17301728 auto secondary = index_type::extract_secondary_key ( obj );
1731- if ( memcmp ( &hana::at_c <index_type::index_number>(secondary_keys), &secondary, sizeof (secondary) ) != 0 ) {
1729+ if ( memcmp ( &std::get <index_type::index_number>(secondary_keys), &secondary, sizeof (secondary) ) != 0 ) {
17321730 auto indexitr = mutableitem.__iters [index_type::number ()];
17331731
17341732 if ( indexitr < 0 ) {
@@ -1739,7 +1737,7 @@ class multi_index
17391737
17401738 secondary_index_db_functions<typename index_type::secondary_key_type>::db_idx_update ( indexitr, payer.value , secondary );
17411739 }
1742- });
1740+ } );
17431741 }
17441742
17451743 /* *
@@ -1935,8 +1933,8 @@ class multi_index
19351933
19361934 internal_use_do_not_use::db_remove_i64 ( objitem.__primary_itr );
19371935
1938- hana:: for_each ( _indices, [&]( auto & idx ) {
1939- typedef typename decltype (+hana::at_c <0 >(idx))::type index_type;
1936+ bluegrass::meta:: for_each (_indices, [&](auto & idx) {
1937+ typedef decltype (std::get <0 >(idx)) index_type;
19401938
19411939 auto i = objitem.__iters [index_type::number ()];
19421940 if ( i < 0 ) {
0 commit comments