Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения

Boost.Hana: boost::hana::set< implementation_defined > Struct Template Reference

Boost , ,

Boost.Hana  1.0.1
Your standard library for metaprogramming
Базовый неупорядоченный контейнер, требующий уникальных ключей<Comparable>и<Hashable>.

Набор представляет собой неупорядоченный контейнер, который может содержать разнородные ключи. Набор требует (и гарантирует) отсутствие дубликатов при вставке новых ключей.

Note
The actual representation of a hana::set is implementation-defined. In particular, one should not take for granted the order of the template parameters and the presence of any additional constructors or assignment operators than what is documented. The canonical way of creating a hana::set is through hana::make_set.

Modeled concepts

  1. Comparable
    Два набора равны, они содержат одни и те же элементы, независимо от порядка.
    // Авторское право Louis Dionne 2013-2016
    // Распространяется под лицензией Boost Software License, версия 1.0.
    // (См. сопроводительный файл LICENSE.md или копию на http://boost.org/LICENSE_1_0.txt)
    пространство именhana =boost::hana;
    intmain() {6]
    hana::make_set(hana::int_c<0>, hana::type_c, hana::int_c<1>
    ==
    hana::make_set(hana::int_c<1>, hana::int_c<0>, hana::type_c
    ;
    hana::make_set(hana::int_c<0>, hana::type_c
    !
    hana::make_set(hana::int_c<1>);
    ;
    ]
    [ORIG_END] -->
  2. Складной
    Складка множества эквивалентна складыванию последовательности его значений. Однако обратите внимание, что значения не обязательно должны быть в каком-либо определенном порядке, поэтому использование представленных здесь складок с операцией, которая не является одновременно коммутативной и ассоциативной, приведет к недетерминистическому поведению.
    // Авторское право Louis Dionne 2013-2016
    // Распространяется по лицензии Boost Software License, Version 1.0.
    // [См. сопроводительный файл LICENSE.md или копия по http://boost.org/LICENSE_1_0.txt]
    ][ORIG_END] -->
  3. Поисковик
    Элементы в наборе действуют как ключи, так и ценности. Поскольку элементы множества уникальны, поиск элемента возвращает либо единственный элемент, равный поисковому значению, либоnothing. Также обратите внимание, чтоoperator[]можно использовать вместо функцииat_key.
    // Авторское право Louis Dionne 2013-2016
    // Распространяется по лицензии Boost Software License, версия 1.0.
    // [См. сопроводительный файл LICENSE.md или копию по адресу http://boost.org/LICENSE_1_0.txt]
    [] [включает<][] [включает<][включает<][включает<][включает<][включает<][включает]][ BOOST_HANA_CONSTANT_CHECKhana::find(xs, hana::int_c<0>) == hana::just (hana::int_c<0>));
    BOOST_HANA_CONSTANT_CHECKhana::find(xs, hana::int_c<3>) == hana:::nothing;
    // оператор [] эквивалентен at_key
    BOOST_HANA_CONSTANT_CHECK[xs [hana::int_c<2>] == hana::int_c<2>]
    // long_c<0>== int_<0>, и поэтому int_<0>найден
    BOOST_HANA_CONSTANT_CHECK[xs [hana::long_c<0&g[ORIG_END] -->

Conversion from any Foldable

Любая структура<Foldable>может быть преобразована в<hana::set>с<to<set_tag>>. Все элементы структуры должны быть составлены по времени<Comparable>. Если структура содержит дублирующие элементы, то в получившемся наборе появится только первая встречаемость. Конверсия из<Foldable>эквивалентна

to<set_tag>(xs) == fold_left(xs, make_set(), insert)

Пример

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
constexpr auto xs = hana::make_tuple(
hana::int_c<1>,
hana::int_c<3>,
hana::type_c<int>,
hana::long_c<1>
);
hana::to<hana::set_tag>(xs)
==
hana::make_set(hana::int_c<1>, hana::int_c<3>, hana::type_c<int>)
);
}

Synopsis of associated functions

constexpr auto difference
 Returns the set-theoretic difference of two sets. More...
 
constexpr auto intersection
 Returns the intersection of two sets. More...
 
template<>
constexpr auto make< set_tag >
 Function object for creating a hana::set. More...
 
constexpr auto make_set = make<set_tag>
 Equivalent to make<set_tag>; provided for convenience. More...
 
constexpr auto insert
 Insert an element in a hana::set. More...
 
constexpr auto erase_key
 Remove an element from a hana::set. More...
 
constexpr auto to_set = to<set_tag>
 Equivalent to to<set_tag>; provided for convenience. More...
 
constexpr auto symmetric_difference
 Returns the symmetric set-theoretic difference of two sets. More...
 
constexpr auto union_
 Returns the union of two sets. More...
 

Friends

template<typename X , typename Y >
constexpr auto operator== (X &&x, Y &&y)
 Equivalent to hana::equal
 
template<typename X , typename Y >
constexpr auto operator!= (X &&x, Y &&y)
 Equivalent to hana::not_equal
 

Public Member Functions

constexpr set (set const &other)=default
 Copy-construct a set from another set. This constructor only exists when all the elements of the set are copy-constructible.
 
constexpr set (set &&other)=default
 Move-construct a set from another set. This constructor only exists when all the elements of the set are move-constructible.
 
template<typename Key >
decltype(auto) constexpr operator[] (Key &&key)
 Equivalent to hana::at_key
 

Associated functions

template<typename implementation_defined >
constexpr auto difference
related
Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Возвращает теоретико-множественное различие двух множеств.

В двух случаях<xs>и<ys>,<difference(xs, ys)>это новый набор, содержащий все элементы<xs>, которыенесодержатся в<ys>. Для любого объекта<x>имеет значение следующее:

x ^in^ difference(xs, ys) if and only if x ^in^ xs && !(x ^in^ ys)
Note
This operation is not commutative, i.e. difference(xs, ys) is not necessarily the same as difference(ys, xs). Indeed, consider the case where xs is empty and ys isn't. Then, difference(xs, ys) is empty but difference(ys, xs) is equal to ys. For the symmetric version of this operation, see symmetric_difference.
Parameters
xsНабор для удаления ценностей.
ysНабор, значения которого удалены от<xs>.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
constexpr auto ys = hana::make_set(hana::int_c<3>, hana::type_c<void>, hana::type_c<int>);
BOOST_HANA_CONSTANT_CHECK(hana::difference(xs, ys) == hana::make_set(hana::int_c<1>, hana::int_c<2>));
BOOST_HANA_CONSTANT_CHECK(hana::difference(ys, xs) == hana::make_set(hana::type_c<void>));
int main() { }
template<typename implementation_defined >
constexpr auto intersection
related
Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Возвращает пересечение двух наборов.

При наличии двух наборов<xs>и<ys><intersection(xs, ys)>новый набор содержит именно те элементы, которые присутствуют как в<xs>, так и в<ys>. Другими словами, для любого объекта<x>:

x ^in^ intersection(xs, ys) if and only if x ^in^ xs && x ^in^ ys
Parameters
xs,ysДва набора для пересечения.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>, hana::int_c<2>);
constexpr auto ys = hana::make_set(hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
BOOST_HANA_CONSTANT_CHECK(hana::intersection(xs, ys) == hana::make_set(hana::int_c<2>));
int main() { }
template<typename implementation_defined >
template<>
constexpr auto make< set_tag >
related
Initial value:
= [](auto&& ...xs) {
return set<implementation_defined>{forwarded(xs)...};
}

Функциональный объект для создания<hana::set>.

При нулевых или более значениях<xs...><make<set_tag>>возвращается<set>, содержащий эти значения. Все значения должны соответствовать времени компиляции<Comparable>, и никакие дублирующие значения не могут быть предоставлены. Чтобы создать<set>из последовательности с возможными дубликатами, используйте<to<set_tag>>вместо этого.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>);
BOOST_HANA_CONSTANT_CHECK(xs == hana::make<hana::set_tag>(hana::int_c<1>, hana::type_c<void>));
int main() { }
template<typename implementation_defined >
constexpr auto make_set = make<set_tag>
related

Для удобства<make<set_tag>>.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>);
BOOST_HANA_CONSTANT_CHECK(xs == hana::make<hana::set_tag>(hana::int_c<1>, hana::type_c<void>));
int main() { }
template<typename implementation_defined >
constexpr auto insert
related
Initial value:
= [](auto&& set, auto&& element) {
return tag-dispatched;
}

Вставьте элемент в<hana::set>.

Если набор уже содержит элемент, который сравнивается равным, то ничего не делается и набор возвращается как есть.

Parameters
setНабор, в который вставить значение.
elementЗначение для вставки. Это должно быть время компиляции<Comparable>.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::type_c<int>);
hana::insert(xs, BOOST_HANA_STRING("abc")) ==
hana::make_set(hana::int_c<0>, hana::type_c<int>, BOOST_HANA_STRING("abc"))
);
hana::insert(xs, hana::int_c<0>) == hana::make_set(hana::int_c<0>, hana::type_c<int>)
);
}
template<typename implementation_defined >
constexpr auto erase_key
related
Initial value:
= [](auto&& set, auto&& element) {
return tag-dispatched;
}

Удалить элемент из<hana::set>.

Возвращает новый набор, содержащий все элементы оригинала, кроме того, который сравнивает<equal>с данным элементом. Если набор не содержит такого элемента, возвращается новый набор, равный исходному набору.

Parameters
setНабор, в котором можно удалить значение.
elementЦенность для удаления. Это должно быть время компиляции<Comparable>.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
int main() {
constexpr auto xs = hana::make_set(hana::int_c<0>, hana::type_c<int>, hana::type_c<void>);
BOOST_HANA_CONSTANT_CHECK(hana::erase_key(xs, hana::type_c<int>) == hana::make_set(hana::int_c<0>, hana::type_c<void>));
BOOST_HANA_CONSTANT_CHECK(hana::erase_key(xs, hana::type_c<char>) == xs);
}
template<typename implementation_defined >
constexpr auto to_set = to<set_tag>
related

Для удобства<to<set_tag>>.

template<typename implementation_defined >
constexpr auto symmetric_difference
related
Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Возвращает симметричное теоретико-множественное различие двух множеств.

При наличии двух наборов<xs>и<ys>,<symmetric_difference(xs, ys)>представляет собой новый набор, содержащий все элементы<xs>, которые не содержатся в<ys>, и все элементы<ys>, которые не содержатся в<xs>. Симметричное различие двух множеств удовлетворяет следующему:

symmetric_difference(xs, ys) == union_(difference(xs, ys), difference(ys, xs))
Parameters
xs,ysДва набора для вычисления симметричной разности.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
constexpr auto ys = hana::make_set(hana::int_c<3>, hana::type_c<void>, hana::type_c<int>);
hana::symmetric_difference(xs, ys) == hana::make_set(hana::int_c<1>, hana::int_c<2>, hana::type_c<void>)
);
int main() { }
template<typename implementation_defined >
constexpr auto union_
related
Initial value:
= [](auto&& xs, auto&& ys) {
return tag-dispatched;
}

Возвращает объединение двух сетов.

При наличии двух наборов<xs>и<ys><union_(xs, ys)>новый набор, содержащий все элементы<xs>и все элементы<ys>, без дубликатов. Для любого объекта<x>, следующее:

x ^in^ union_(xs, ys) if and only if x ^in^ xs || x ^in^ ys
Parameters
xs,ysДва набора для вычисления союза.

Example

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
namespace hana = boost::hana;
constexpr auto xs = hana::make_set(hana::int_c<1>, hana::type_c<void>, hana::int_c<2>);
constexpr auto ys = hana::make_set(hana::int_c<2>, hana::type_c<int>, hana::int_c<3>);
BOOST_HANA_CONSTANT_CHECK(hana::union_(xs, ys) == hana::make_set(
hana::int_c<1>, hana::int_c<2>, hana::int_c<3>, hana::type_c<void>, hana::type_c<int>
));
int main() { }

Статья Boost.Hana: boost::hana::set< implementation_defined > Struct Template Reference раздела может быть полезна для разработчиков на c++ и boost.




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: ::


реклама


©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru

Время компиляции файла: 2024-08-30 11:47:00
2025-05-20 01:05:31/0.0081510543823242/1