Skip to content

Commit

Permalink
Update libcxx/multimap
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Nov 28, 2023
1 parent adcb15f commit 9628891
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 32 deletions.
8 changes: 8 additions & 0 deletions test/sources/LibcxxMultiMapTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ LIBCXX_TEST_BEGIN(iterator)
#include "libcxx/multimap/iterator.pass.cpp"
LIBCXX_TEST_END

LIBCXX_TEST_BEGIN(iterator_types)
#include "libcxx/multimap/iterator_types.pass.cpp"
LIBCXX_TEST_END

//LIBCXX_TEST_BEGIN(max_size)
//#include "libcxx/multimap/max_size.pass.cpp"
//LIBCXX_TEST_END
Expand Down Expand Up @@ -206,6 +210,10 @@ LIBCXX_TEST_BEGIN(ops_contains)
#include "libcxx/multimap/multimap.ops/contains.pass.cpp"
LIBCXX_TEST_END

LIBCXX_TEST_BEGIN(ops_contains_transparent)
#include "libcxx/multimap/multimap.ops/contains_transparent.pass.cpp"
LIBCXX_TEST_END

LIBCXX_TEST_BEGIN(ops_count)
#include "libcxx/multimap/multimap.ops/count.pass.cpp"
LIBCXX_TEST_END
Expand Down
62 changes: 40 additions & 22 deletions test/sources/LibcxxTreeMultiMapTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,54 @@

#include "../../include/momo/stdish/map.h"

#define LIBCXX_TEST_PREFIX "libcxx_test_tree_multimap"
namespace libcxx_test_tree_multimap
{
template<typename TKey, typename TMapped,
typename TLessFunc = std::less<TKey>,
typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
using multimap = momo::stdish::multimap<TKey, TMapped, TLessFunc, TAllocator,
momo::TreeMap<TKey, TMapped, momo::TreeTraitsStd<TKey, TLessFunc, true,
momo::TreeNode<4, 2, momo::MemPoolParams<1>, false>>,
momo::MemManagerStd<TAllocator>,
momo::TreeMapKeyValueTraits<TKey, TMapped, momo::MemManagerStd<TAllocator>, false>,
momo::TreeMapSettings>>;
#include "LibcxxMultiMapTests.h"

namespace std
{
using namespace ::std;

template<typename TKey, typename TMapped,
typename TLessFunc = std::less<TKey>,
typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
using multimap = momo::stdish::multimap<TKey, TMapped, TLessFunc, TAllocator,
momo::TreeMap<TKey, TMapped, momo::TreeTraitsStd<TKey, TLessFunc, true,
momo::TreeNode<4, 2, momo::MemPoolParams<1>, false>>,
momo::MemManagerStd<TAllocator>,
momo::TreeMapKeyValueTraits<TKey, TMapped, momo::MemManagerStd<TAllocator>, false>,
momo::TreeMapSettings>>;
}

using std::multimap;

#define LIBCXX_TEST_PREFIX "libcxx_test_tree_multimap"
#include "LibcxxMultiMapTests.h"
#undef LIBCXX_TEST_PREFIX
}

#define LIBCXX_TEST_PREFIX "libcxx_test_tree_multimap_vp"
namespace libcxx_test_tree_multimap_vp
{
template<typename TKey, typename TMapped,
typename TLessFunc = std::less<TKey>,
typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
using multimap = momo::stdish::multimap<TKey, TMapped, TLessFunc, TAllocator,
momo::TreeMap<TKey, TMapped, momo::TreeTraitsStd<TKey, TLessFunc, true,
momo::TreeNode<4, 2, momo::MemPoolParams<1>, true>>,
momo::MemManagerStd<TAllocator>,
momo::TreeMapKeyValueTraits<TKey, TMapped, momo::MemManagerStd<TAllocator>, true>,
momo::TreeMapSettings>>;
#include "LibcxxMultiMapTests.h"

namespace std
{
using namespace ::std;

template<typename TKey, typename TMapped,
typename TLessFunc = std::less<TKey>,
typename TAllocator = std::allocator<std::pair<const TKey, TMapped>>>
using multimap = momo::stdish::multimap<TKey, TMapped, TLessFunc, TAllocator,
momo::TreeMap<TKey, TMapped, momo::TreeTraitsStd<TKey, TLessFunc, true,
momo::TreeNode<4, 2, momo::MemPoolParams<1>, true>>,
momo::MemManagerStd<TAllocator>,
momo::TreeMapKeyValueTraits<TKey, TMapped, momo::MemManagerStd<TAllocator>, true>,
momo::TreeMapSettings>>;
}

using std::multimap;

#define LIBCXX_TEST_PREFIX "libcxx_test_tree_multimap_vp"
#include "LibcxxMultiMapTests.h"
#undef LIBCXX_TEST_PREFIX
}

#endif // TEST_LIBCXX_TREE_MAP
68 changes: 68 additions & 0 deletions test/sources/libcxx/multimap/iterator_types.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Modified for https://github.com/morzhovets/momo project.
//
//===----------------------------------------------------------------------===//


template <class Map, class ValueTp, class PtrT, class CPtrT>
void testMap() {
typedef typename Map::difference_type Diff;
{
#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
typedef typename Map::iterator It;
#else
typedef std::iterator_traits<typename Map::iterator> It;
#endif
#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
static_assert((std::is_same<typename It::value_type, ValueTp>::value), "");
static_assert((std::is_same<typename It::reference, ValueTp&>::value), "");
static_assert((std::is_same<typename It::pointer, PtrT>::value), "");
#endif
static_assert((std::is_same<typename It::difference_type, Diff>::value), "");
}
{
#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
typedef typename Map::const_iterator It;
#else
typedef std::iterator_traits<typename Map::const_iterator> It;
#endif
#ifdef LIBCPP_HAS_BAD_NEWS_FOR_MOMO
static_assert((std::is_same<typename It::value_type, ValueTp>::value), "");
static_assert((std::is_same<typename It::reference, ValueTp const&>::value), "");
static_assert((std::is_same<typename It::pointer, CPtrT>::value), "");
#endif
static_assert((std::is_same<typename It::difference_type, Diff>::value), "");
}
}


int main(int, char**) {
{
typedef std::multimap<int, int> Map;
typedef std::pair<const int, int> ValueTp;
testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
}
{
typedef std::pair<const int, int> ValueTp;
typedef test_allocator<ValueTp> Alloc;
typedef std::multimap<int, int, std::less<int>, Alloc> Map;
testMap<Map, ValueTp, ValueTp*, ValueTp const*>();
}
#if TEST_STD_VER >= 11
{
typedef std::pair<const int, int> ValueTp;
typedef min_allocator<ValueTp> Alloc;
typedef std::multimap<int, int, std::less<int>, Alloc> Map;
testMap<Map, ValueTp, min_pointer<ValueTp>, min_pointer<const ValueTp>>();
}
#endif

return 0;
}
17 changes: 7 additions & 10 deletions test/sources/libcxx/multimap/multimap.ops/contains.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

// UNSUPPORTED: c++03, c++11, c++14, c++17

//#include <cassert>
//#include <map>

// <map>

// bool contains(const key_type& x) const;
Expand All @@ -32,21 +29,21 @@ void test(B bad, Pairs... args) {

struct E { int a = 1; double b = 1; char c = 1; };

void main()
int main(int, char**)
{
{
test<multimap<char, int>, std::pair<char, int> >(
test<std::multimap<char, int>, std::pair<char, int> >(
'e', std::make_pair('a', 10), std::make_pair('b', 11),
std::make_pair('c', 12), std::make_pair('d', 13));

test<multimap<char, char>, std::pair<char, char> >(
test<std::multimap<char, char>, std::pair<char, char> >(
'e', std::make_pair('a', 'a'), std::make_pair('b', 'a'),
std::make_pair('c', 'a'), std::make_pair('d', 'b'));

#ifndef LIBCPP_HAS_NO_TRANSPARENT_OPERATORS
test<multimap<int, E, std::less<>>, std::pair<int, E> >(
int8_t{-1}, std::make_pair(1, E{}), std::make_pair(2, E{}),
test<std::multimap<int, E>, std::pair<int, E> >(
-1, std::make_pair(1, E{}), std::make_pair(2, E{}),
std::make_pair(3, E{}), std::make_pair(4, E{}));
#endif
}

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Modified for https://github.com/morzhovets/momo project.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17

// <map>

// template<class K> bool contains(const K& x) const; // C++20

struct Comp {
using is_transparent = void;

bool operator()(const std::pair<int, int>& lhs,
const std::pair<int, int>& rhs) const {
return lhs < rhs;
}

bool operator()(const std::pair<int, int>& lhs, int rhs) const {
return lhs.first < rhs;
}

bool operator()(int lhs, const std::pair<int, int>& rhs) const {
return lhs < rhs.first;
}
};

template <typename Container>
void test() {
Container s{{{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}};

assert(s.contains(1));
assert(!s.contains(-1));
}

int main(int, char**) {
test<std::multimap<std::pair<int, int>, int, Comp> >();

return 0;
}

0 comments on commit 9628891

Please sign in to comment.