-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef BURST_RANGE_ADAPTOR_TO_SET_HPP | ||
#define BURST_RANGE_ADAPTOR_TO_SET_HPP | ||
|
||
#include <burst/range/adaptor/adaptor.hpp> | ||
#include <burst/container/make_set.hpp> | ||
|
||
namespace burst | ||
{ | ||
struct make_set_t | ||
{ | ||
template <typename... Xs> | ||
constexpr auto operator () (Xs &&... xs) const | ||
{ | ||
return make_set(std::forward<Xs>(xs)...); | ||
} | ||
}; | ||
|
||
/*! | ||
\brief | ||
Инструмент для конструирования класса std::set через конвейер | ||
\details | ||
Вызовы | ||
\code{.cpp} | ||
range | to_set | ||
range | to_set(std::greater<>{}) | ||
\endcode | ||
соответственно эквивалентны вызовам | ||
\code{.cpp} | ||
make_set(range) | ||
make_set(range, std::greater<>{}) | ||
\endcode | ||
\see make_set | ||
*/ | ||
constexpr auto to_set = make_adaptor_trigger(make_set_t{}); | ||
} // namespace burst | ||
|
||
#endif // BURST_RANGE_ADAPTOR_TO_SET_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <burst/range/adaptor/to_set.hpp> | ||
|
||
#include <doctest/doctest.h> | ||
|
||
#include <boost/range/irange.hpp> | ||
|
||
#include <forward_list> | ||
#include <functional> | ||
#include <initializer_list> | ||
#include <set> | ||
|
||
TEST_SUITE("to_set") | ||
{ | ||
TEST_CASE("Может работать с rvalue-диапазоном") | ||
{ | ||
const auto s = boost::irange<int>(0, 10) | burst::to_set; | ||
CHECK(s == std::set<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); | ||
} | ||
|
||
TEST_CASE("Может работать с lvalue-диапазоном") | ||
{ | ||
const auto fl = std::forward_list<char>{'a', 'b', 'c'}; | ||
|
||
const auto s = fl | burst::to_set; | ||
CHECK(s == std::set<char>{'a', 'b', 'c'}); | ||
} | ||
|
||
TEST_CASE("Может работать со списком инициализации") | ||
{ | ||
const auto il = std::initializer_list<char>{'a', 'b', 'c'}; | ||
const auto s = il | burst::to_set; | ||
CHECK(s == std::set<char>{'a', 'b', 'c'}); | ||
} | ||
|
||
TEST_CASE("Предусматривает задание отношения порядка") | ||
{ | ||
const auto fl = std::forward_list<char>{1, 2, 3}; | ||
|
||
const auto s = fl | burst::to_set(std::greater<>{}); | ||
CHECK(s == std::set<char, std::greater<>>{3, 2, 1}); | ||
} | ||
} |