diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 1b2628b..a1f8583 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -178,33 +178,39 @@ struct type_info<> { } // namespace impl -template -std::vector> init_wrappers() +template +static const fc::array + init_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0) { - return std::vector>(); + return fc::array(); } -template -std::vector> init_wrappers() +template +static const fc::array + init_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0 ) { - std::vector> result - = init_wrappers(); - result.insert( result.begin(), [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); } ); + fc::array result; + if( !funcs ) funcs = result.begin(); + *funcs++ = [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); }; + init_wrappers( v, d, funcs ); return result; } -template -std::vector> init_const_wrappers() +template +static const fc::array + init_const_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0 ) { - return std::vector>(); + return fc::array(); } -template -std::vector> init_const_wrappers() +template +static const fc::array + init_const_wrappers( Visitor& v, Data d, typename Visitor::result_type(**funcs)(Visitor&,Data) = 0 ) { - std::vector> result - = init_const_wrappers(); - result.insert( result.begin(), [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); } ); + fc::array result; + if( !funcs ) funcs = result.begin(); + *funcs++ = [] ( Visitor& v, Data d ) { return v( *reinterpret_cast( d ) ); }; + init_const_wrappers( v, d, funcs ); return result; } @@ -361,7 +367,7 @@ public: template static typename visitor::result_type visit( tag_type tag, visitor& v, void* data ) { - static auto wrappers = init_wrappers(); + static const auto wrappers = init_wrappers::count,visitor,void*,Types...>( v, data ); FC_ASSERT( tag >= 0 && tag < count(), "Unsupported type ${tag}!", ("tag",tag) ); return wrappers[tag]( v, data ); } @@ -369,7 +375,7 @@ public: template static typename visitor::result_type visit( tag_type tag, const visitor& v, void* data ) { - static auto wrappers = init_wrappers(); + static const auto wrappers = init_wrappers::count,const visitor,void*,Types...>( v, data ); FC_ASSERT( tag >= 0 && tag < count(), "Unsupported type ${tag}!", ("tag",tag) ); return wrappers[tag]( v, data ); } @@ -377,7 +383,7 @@ public: template static typename visitor::result_type visit( tag_type tag, visitor& v, const void* data ) { - static auto wrappers = init_const_wrappers(); + static const auto wrappers = init_const_wrappers::count,visitor,const void*,Types...>( v, data ); FC_ASSERT( tag >= 0 && tag < count(), "Unsupported type ${tag}!", ("tag",tag) ); return wrappers[tag]( v, data ); } @@ -385,7 +391,7 @@ public: template static typename visitor::result_type visit( tag_type tag, const visitor& v, const void* data ) { - static auto wrappers = init_const_wrappers(); + static const auto wrappers = init_const_wrappers::count,const visitor,const void*,Types...>( v, data ); FC_ASSERT( tag >= 0 && tag < count(), "Unsupported type ${tag}!", ("tag",tag) ); return wrappers[tag]( v, data ); }