Added C++03 portable aliases and tests. Fixes #129 ("Alias templates for small_flat_[multi]{set|map} using small_vector as container")

This commit is contained in:
Ion Gaztañaga
2020-05-25 01:50:23 +02:00
parent 8b8a0c05a5
commit 80d742f860
4 changed files with 77 additions and 1 deletions

View File

@@ -1319,7 +1319,8 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes_boost_1_74_00 Boost 1.74 Release] [section:release_notes_boost_1_74_00 Boost 1.74 Release]
* Fixed bugs: * Fixed bugs/issues:
* [@https://github.com/boostorg/container/issues/129 GitHub #129: ['"Alias templates for small_flat_[multi]{set|map} using small_vector as container"]].
* [@https://github.com/boostorg/container/issues/144 GitHub #144: ['"GCC suggest-override warnings"]]. * [@https://github.com/boostorg/container/issues/144 GitHub #144: ['"GCC suggest-override warnings"]].
* [@https://github.com/boostorg/container/issues/145 GitHub #145: ['"Allocations not handled correctly in some cases of vector move with unequal allocators"]]. * [@https://github.com/boostorg/container/issues/145 GitHub #145: ['"Allocations not handled correctly in some cases of vector move with unequal allocators"]].
* [@https://github.com/boostorg/container/pull/146 GitHub #146: ['"Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Addition needed for Embarcardero clang-based compilers"]]. * [@https://github.com/boostorg/container/pull/146 GitHub #146: ['"Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Addition needed for Embarcardero clang-based compilers"]].

View File

@@ -220,6 +220,52 @@ using small_flat_multimap = flat_multimap<Key, T, Compare, small_vector<std::pai
#endif // #ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES #endif // #ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
//! A portable metafunction to obtain a small_flat_set
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_set_of
{
typedef flat_set<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_multiset
template < class Key
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_multiset_of
{
typedef flat_multiset<Key, Compare, small_vector<Key, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_map
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_map_of
{
typedef flat_map<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
//! A portable metafunction to obtain a small_flat_multimap
template < class Key
, class T
, std::size_t N
, class Compare = std::less<Key>
, class SmallVectorAllocator = void
, class SmallVectorOptions = void >
struct small_flat_multimap_of
{
typedef flat_multimap<Key, T, Compare, small_vector<std::pair<Key, T>, N, SmallVectorAllocator, SmallVectorOptions> > type;
};
template <class CharT template <class CharT
,class Traits = std::char_traits<CharT> ,class Traits = std::char_traits<CharT>
,class Allocator = void > ,class Allocator = void >

View File

@@ -13,6 +13,7 @@
#include <boost/container/stable_vector.hpp> #include <boost/container/stable_vector.hpp>
#include <boost/container/vector.hpp> #include <boost/container/vector.hpp>
#include <boost/container/deque.hpp> #include <boost/container/deque.hpp>
#include <boost/static_assert.hpp>
#include <boost/container/detail/container_or_allocator_rebind.hpp> #include <boost/container/detail/container_or_allocator_rebind.hpp>
@@ -99,6 +100,20 @@ int main()
return 1; return 1;
} }
} }
{
using namespace boost::container;
using boost::container::dtl::is_same;
typedef flat_map<int, float, std::less<int>, small_vector<std::pair<int, float>, 10> > map_container_t;
typedef flat_multimap<int, float, std::less<int>, small_vector<std::pair<int, float>, 10> > multimap_container_t;
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
BOOST_STATIC_ASSERT(( is_same<map_container_t, small_flat_map<int, float, 10> >::value ));
BOOST_STATIC_ASSERT(( is_same<multimap_container_t, small_flat_multimap<int, float, 10> >::value ));
#endif
BOOST_STATIC_ASSERT(( is_same<map_container_t, small_flat_map_of<int, float, 10>::type >::value ));
BOOST_STATIC_ASSERT(( is_same<multimap_container_t, small_flat_multimap_of<int, float, 10>::type >::value ));
}
return 0; return 0;
} }

View File

@@ -13,6 +13,7 @@
#include <boost/container/stable_vector.hpp> #include <boost/container/stable_vector.hpp>
#include <boost/container/vector.hpp> #include <boost/container/vector.hpp>
#include <boost/container/deque.hpp> #include <boost/container/deque.hpp>
#include <boost/static_assert.hpp>
#include <boost/container/detail/container_or_allocator_rebind.hpp> #include <boost/container/detail/container_or_allocator_rebind.hpp>
@@ -96,6 +97,19 @@ int main()
return 1; return 1;
} }
} }
{
using namespace boost::container;
using boost::container::dtl::is_same;
typedef flat_set<int, std::less<int>, small_vector<int, 10> > set_container_t;
typedef flat_multiset<int, std::less<int>, small_vector<int, 10> > multiset_container_t;
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
BOOST_STATIC_ASSERT(( is_same<set_container_t, small_flat_set<int, 10> >::value ));
BOOST_STATIC_ASSERT(( is_same<multiset_container_t, small_flat_multiset<int, 10> >::value ));
#endif
BOOST_STATIC_ASSERT(( is_same<set_container_t, small_flat_set_of<int, 10>::type >::value ));
BOOST_STATIC_ASSERT(( is_same<multiset_container_t, small_flat_multiset_of<int, 10>::type >::value ));
}
return 0; return 0;
} }