Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/reference/bimap.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ this tags.
template< class InputIterator >
bimap(InputIterator first,InputIterator last);

bimap(std::initializer_list<relation> init);

bimap(const bimap &);

bimap& operator=(const bimap& b);
Expand Down Expand Up @@ -344,6 +346,10 @@ acceptance by the collection types of the `bimap`.
* [link complexity_signature_explanation
[*Complexity:]] O(m*H(m)), where m is the number of elements in `[first,last)`.

bimap(std::initializer_list<relation> init);

* [*Effects:] Equivalent to `bimap(init.begin(), init.end())`.
* [*Complexity:] O(init.size()*H(init.size())).

bimap(const bimap & x);

Expand Down
4 changes: 4 additions & 0 deletions doc/release_notes.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ http://www.boost.org/LICENSE_1_0.txt)

[section Release notes]

[heading Boost 1.92 release]

* Added `std::initializer_list` constructor ([@https://github.com/boostorg/bimap/pull/31 PR#31]).

[heading Boost 1.91 release]

* Adapted the library to work with the latest updates of Boost.MultiIndex ([@https://github.com/boostorg/bimap/pull/49 PR#49]).
Expand Down
56 changes: 50 additions & 6 deletions test/test_bimap.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
// Copyright (c) 2024 Joaquin M Lopez Munoz
// Copyright (c) 2024-2026 Joaquin M Lopez Munoz
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
Expand All @@ -20,9 +20,11 @@
#include <cassert>
#include <algorithm>
#include <iterator>
#include <vector>

#include <boost/lambda/lambda.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits/has_equal_to.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/utility.hpp>
#include <boost/next_prior.hpp>
Expand Down Expand Up @@ -637,24 +639,66 @@ void test_unordered_set_unordered_multiset_bimap(Bimap & b,
test_unique_container(b.right, rd);
}

template< class Bimap, class Data >
std::vector<typename Bimap::value_type> make_value_type_vector(
const Data& d, std::size_t n)
{
std::vector<typename Bimap::value_type> res;
auto first = d.begin(), last = d.end();
while(n--) {
res.push_back(std::next(first) == last? *first: *++first);
}
return res;
}

template< class Bimap >
bool check_equal(const Bimap& b1, const Bimap& b2, boost::true_type)
{
return b1 == b2;
}

template< class Bimap >
bool check_equal(const Bimap& b1, const Bimap& b2, boost::false_type)
{
if(b1.size() != b2.size()) return false;
for(const auto& x: b1) {
if(std::find(b2.begin(), b2.end(), x) == b2.end()) return false;
}
for(const auto& x: b2) {
if(std::find(b1.begin(), b1.end(), x) == b1.end()) return false;
}
return true;
}

template< class Bimap >
bool check_equal(const Bimap& b1, const Bimap& b2)
{
return check_equal(b1, b2, boost::has_equal_to<Bimap>{});
}

template< class Bimap, class Data>
void test_bimap_init_copy_swap(const Data&d)
{
Bimap b1(d.begin(),d.end());
Bimap b2( b1 );
BOOST_TEST( b1 == b2 );

BOOST_TEST( check_equal(b1, b2) );

auto v = make_value_type_vector<Bimap>(d, 5);
Bimap b3({v[0], v[1], v[2], v[3], v[4]});
Bimap b4(v.begin(), v.end());
BOOST_TEST( check_equal(b3, b4) );

b2.clear();
b2 = b1;
BOOST_TEST( b2 == b1 );
BOOST_TEST( check_equal(b2, b1) );

b2.clear();
b2.left = b1.left;
BOOST_TEST( b2 == b1 );
BOOST_TEST( check_equal(b2, b1) );

b2.clear();
b2.right = b1.right;
BOOST_TEST( b2 == b1 );
BOOST_TEST( check_equal(b2, b1) );

b1.clear();
b2.swap(b1);
Expand Down
4 changes: 3 additions & 1 deletion test/test_bimap_ordered.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
// Copyright (c) 2024 Joaquin M Lopez Munoz
// Copyright (c) 2024-2026 Joaquin M Lopez Munoz
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -74,6 +74,8 @@ void test_bimap()
data.insert( bm_type::value_type(4,0.4) );

bm_type bm;

test_bimap_init_copy_swap<bm_type>(data) ;
test_set_set_bimap(bm,data,left_data,right_data);
}
//--------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion test/test_bimap_unordered.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Boost.Bimap
//
// Copyright (c) 2006-2007 Matias Capeletto
// Copyright (c) 2024 Joaquin M Lopez Munoz
// Copyright (c) 2024-2026 Joaquin M Lopez Munoz
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
Expand Down Expand Up @@ -77,6 +77,7 @@ void test_bimap()

bm_type bm;

test_bimap_init_copy_swap<bm_type>(data) ;
test_unordered_set_unordered_multiset_bimap(
bm,data,left_data,right_data
);
Expand Down
Loading