Skip to content

Commit c4384f4

Browse files
authored
Merge pull request #108 from AntelopeIO/remove-boost
Remove boost from eosiolib and native libraries
2 parents fb549b6 + cf2f1e9 commit c4384f4

File tree

12 files changed

+1117
-101
lines changed

12 files changed

+1117
-101
lines changed

libraries/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ set(CMAKE_CXX_EXTENSIONS ON)
2121
add_subdirectory(libc)
2222
add_subdirectory(libc++)
2323
add_subdirectory(eosiolib)
24-
add_subdirectory(boost)
2524
add_subdirectory(rt)
2625

2726
if (ENABLE_NATIVE_COMPILER)

libraries/eosiolib/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ if (${PARENT_PROJECT_NAME} STREQUAL "cdt_tools")
1212
${HEADERS} )
1313
target_compile_definitions(${PROJECT_NAME} PUBLIC EOSIO_NATIVE EOSIOLIB_DISABLE_MALLOC)
1414
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/../libraries/eosiolib/core
15-
${CMAKE_SOURCE_DIR}/../libraries/boost/include
1615
${CMAKE_SOURCE_DIR}/../libraries/meta_refl/include)
1716
target_compile_options(${PROJECT_NAME} PUBLIC -fPIC -fexceptions -fno-rtti)
1817
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
@@ -50,8 +49,7 @@ else()
5049
${CMAKE_SOURCE_DIR}/libc/cdt-musl/src/crypt
5150
${CMAKE_SOURCE_DIR}/libc/cdt-musl/arch/eos
5251
${CMAKE_SOURCE_DIR}/libc++/cdt-libcxx/include
53-
${CMAKE_SOURCE_DIR}
54-
${CMAKE_SOURCE_DIR}/boost/include)
52+
${CMAKE_SOURCE_DIR})
5553

5654
target_link_libraries( eosio c c++ )
5755
add_custom_command( TARGET eosio POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:eosio> ${BASE_BINARY_DIR}/lib )

libraries/eosiolib/contracts/eosio/action.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,14 @@
44
*/
55
#pragma once
66
#include <cstdlib>
7+
#include <type_traits>
78

89
#include "../../core/eosio/serialize.hpp"
910
#include "../../core/eosio/datastream.hpp"
1011
#include "../../core/eosio/name.hpp"
1112
#include "../../core/eosio/ignore.hpp"
1213
#include "../../core/eosio/time.hpp"
1314

14-
#include <boost/preprocessor/variadic/size.hpp>
15-
#include <boost/preprocessor/variadic/to_tuple.hpp>
16-
#include <boost/preprocessor/tuple/enum.hpp>
17-
#include <boost/preprocessor/facilities/overload.hpp>
18-
1915
namespace eosio {
2016

2117
namespace internal_use_do_not_use {
@@ -570,7 +566,7 @@ ::eosio::inline_dispatcher<decltype(&CONTRACT_CLASS::FUNCTION_NAME), ACTION_NAME
570566
#define INLINE_ACTION_SENDER2( CONTRACT_CLASS, NAME )\
571567
INLINE_ACTION_SENDER3( CONTRACT_CLASS, NAME, ::eosio::name(#NAME) )
572568

573-
#define INLINE_ACTION_SENDER(...) BOOST_PP_OVERLOAD(INLINE_ACTION_SENDER,__VA_ARGS__)(__VA_ARGS__)
569+
#define INLINE_ACTION_SENDER(...) BLUEGRASS_META_OVERLOAD(INLINE_ACTION_SENDER,__VA_ARGS__)(__VA_ARGS__)
574570

575571
/**
576572
* Send an inline-action from inside a contract.
@@ -599,5 +595,4 @@ INLINE_ACTION_SENDER3( CONTRACT_CLASS, NAME, ::eosio::name(#NAME) )
599595
*/
600596

601597
#define SEND_INLINE_ACTION( CONTRACT, NAME, ... )\
602-
INLINE_ACTION_SENDER(std::decay_t<decltype(CONTRACT)>, NAME)( (CONTRACT).get_self(),\
603-
BOOST_PP_TUPLE_ENUM(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), BOOST_PP_VARIADIC_TO_TUPLE(__VA_ARGS__)) );
598+
INLINE_ACTION_SENDER(std::decay_t<decltype(CONTRACT)>, NAME)( (CONTRACT).get_self(),__VA_ARGS__)

libraries/eosiolib/contracts/eosio/dispatcher.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#pragma once
22
#include "action.hpp"
33

4-
#include <boost/fusion/adapted/std_tuple.hpp>
5-
#include <boost/fusion/include/std_tuple.hpp>
6-
7-
#include <boost/mp11/tuple.hpp>
4+
#include <bluegrass/meta/preprocessor.hpp>
5+
#include <tuple>
86

97
namespace eosio {
108

@@ -85,7 +83,7 @@ namespace eosio {
8583
((&inst)->*func)( a... );
8684
};
8785

88-
boost::mp11::tuple_apply( f2, args );
86+
std::apply( f2, args );
8987
if ( max_stack_buffer_size < size ) {
9088
free(buffer);
9189
}
@@ -95,14 +93,14 @@ namespace eosio {
9593
/// @cond INTERNAL
9694

9795
// Helper macro for EOSIO_DISPATCH_INTERNAL
98-
#define EOSIO_DISPATCH_INTERNAL( r, OP, elem ) \
99-
case eosio::name( BOOST_PP_STRINGIZE(elem) ).value: \
96+
#define EOSIO_DISPATCH_INTERNAL( OP, elem ) \
97+
case eosio::name( BLUEGRASS_META_STRINGIZE(elem) ).value: \
10098
eosio::execute_action( eosio::name(receiver), eosio::name(code), &OP::elem ); \
10199
break;
102100

103101
// Helper macro for EOSIO_DISPATCH
104102
#define EOSIO_DISPATCH_HELPER( TYPE, MEMBERS ) \
105-
BOOST_PP_SEQ_FOR_EACH( EOSIO_DISPATCH_INTERNAL, TYPE, MEMBERS )
103+
BLUEGRASS_META_FOREACH_SEQ( EOSIO_DISPATCH_INTERNAL, TYPE, MEMBERS )
106104

107105
/// @endcond
108106

libraries/eosiolib/contracts/eosio/multi_index.hpp

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
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

304305
namespace _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 ) {

libraries/eosiolib/core/eosio/datastream.hpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#pragma once
66
#include "check.hpp"
77
#include "varint.hpp"
8+
#include <bluegrass/meta/for_each.hpp>
89

910
#include <list>
1011
#include <queue>
@@ -18,14 +19,6 @@
1819

1920
#include <cstring>
2021

21-
#include <boost/fusion/algorithm/iteration/for_each.hpp>
22-
#include <boost/fusion/include/for_each.hpp>
23-
#include <boost/fusion/adapted/std_tuple.hpp>
24-
#include <boost/fusion/include/std_tuple.hpp>
25-
26-
#include <boost/mp11/tuple.hpp>
27-
#include <boost/pfr.hpp>
28-
2922
namespace eosio {
3023

3124
/**
@@ -866,7 +859,7 @@ datastream<Stream>& operator >> ( datastream<Stream>& ds, std::map<K,V>& m ) {
866859
*/
867860
template<typename Stream, typename... Args>
868861
datastream<Stream>& operator<<( datastream<Stream>& ds, const std::tuple<Args...>& t ) {
869-
boost::fusion::for_each( t, [&]( const auto& i ) {
862+
bluegrass::meta::for_each( t, [&]( const auto& i ) {
870863
ds << i;
871864
});
872865
return ds;
@@ -883,7 +876,7 @@ datastream<Stream>& operator<<( datastream<Stream>& ds, const std::tuple<Args...
883876
*/
884877
template<typename Stream, typename... Args>
885878
datastream<Stream>& operator>>( datastream<Stream>& ds, std::tuple<Args...>& t ) {
886-
boost::fusion::for_each( t, [&]( auto& i ) {
879+
bluegrass::meta::for_each( t, [&]( auto& i ) {
887880
ds >> i;
888881
});
889882
return ds;
@@ -900,7 +893,7 @@ datastream<Stream>& operator>>( datastream<Stream>& ds, std::tuple<Args...>& t )
900893
*/
901894
template<typename DataStream, typename T, std::enable_if_t<std::is_class<T>::value && _datastream_detail::is_datastream<DataStream>::value>* = nullptr>
902895
DataStream& operator<<( DataStream& ds, const T& v ) {
903-
boost::pfr::for_each_field(v, [&](const auto& field) {
896+
bluegrass::meta::for_each_field(v, [&](const auto& field) {
904897
ds << field;
905898
});
906899
return ds;
@@ -917,7 +910,7 @@ DataStream& operator<<( DataStream& ds, const T& v ) {
917910
*/
918911
template<typename DataStream, typename T, std::enable_if_t<std::is_class<T>::value && _datastream_detail::is_datastream<DataStream>::value>* = nullptr>
919912
DataStream& operator>>( DataStream& ds, T& v ) {
920-
boost::pfr::for_each_field(v, [&](auto& field) {
913+
bluegrass::meta::for_each_field(v, [&](auto& field) {
921914
ds >> field;
922915
});
923916
return ds;

0 commit comments

Comments
 (0)