29 #ifndef PIRANHA_ARRAY_KEY_HPP 30 #define PIRANHA_ARRAY_KEY_HPP 35 #include <initializer_list> 40 #include <type_traits> 44 #include <piranha/config.hpp> 46 #include <piranha/math.hpp> 47 #include <piranha/safe_cast.hpp> 48 #include <piranha/small_vector.hpp> 49 #include <piranha/symbol_utils.hpp> 85 template <
typename T,
typename Derived,
typename S = std::
integral_constant<std::
size_t, 0u>>
91 PIRANHA_TT_CHECK(std::is_constructible, T,
int);
123 template <
typename U>
124 using init_list_enabler = enable_if_t<std::is_constructible<container_type, std::initializer_list<U>>::value,
int>;
138 template <
typename U, init_list_enabler<U> = 0>
161 template <
typename U>
162 using generic_ctor_enabler = enable_if_t<has_safe_cast<value_type, U>::value,
int>;
184 template <
typename U,
typename Derived2,
typename S2,
generic_ctor_enabler<U> = 0>
187 if (unlikely(other.
size() != args.size())) {
189 "inconsistent sizes in the generic array_key constructor: the size of the array (" 190 + std::to_string(other.
size()) +
") differs from the size of the symbol set (" 191 + std::to_string(args.size()) +
")");
200 PIRANHA_TT_CHECK(std::is_base_of,
array_key, Derived);
370 if (unlikely(std::get<0>(sbe) != args.size())) {
371 piranha_throw(std::invalid_argument,
"invalid symbol set for trim_identify(): the size of the array (" 372 + std::to_string(std::get<0>(sbe))
373 +
") differs from the size of the reference symbol set (" 374 + std::to_string(args.size()) +
")");
376 if (unlikely(std::get<0>(sbe) != trim_mask.size())) {
378 "invalid mask for trim_identify(): the size of the array (" + std::to_string(std::get<0>(sbe))
379 +
") differs from the size of the mask (" + std::to_string(trim_mask.size()) +
")");
381 for (decltype(trim_mask.size()) i = 0; std::get<1>(sbe) != std::get<2>(sbe); ++i, ++std::get<1>(sbe)) {
412 if (unlikely(std::get<0>(sbe) != args.size())) {
413 piranha_throw(std::invalid_argument,
"invalid arguments set for trim(): the size of the array (" 414 + std::to_string(std::get<0>(sbe))
415 +
") differs from the size of the reference symbol set (" 416 + std::to_string(args.size()) +
")");
418 if (unlikely(std::get<0>(sbe) != trim_mask.size())) {
420 "invalid mask for trim(): the size of the array (" + std::to_string(std::get<0>(sbe))
421 +
") differs from the size of the mask (" + std::to_string(trim_mask.size()) +
")");
424 for (decltype(trim_mask.size()) i = 0; std::get<1>(sbe) != std::get<2>(sbe); ++i, ++std::get<1>(sbe)) {
426 retval.push_back(*std::get<1>(sbe));
434 template <
typename U>
435 using add_t = decltype(std::declval<U const &>().add(std::declval<U &>(), std::declval<U const &>()));
436 template <
typename U>
437 using sub_t = decltype(std::declval<U const &>().sub(std::declval<U &>(), std::declval<U const &>()));
438 template <
typename U>
439 using add_enabler = enable_if_t<is_detected<add_t, U>::value,
int>;
440 template <
typename U>
441 using sub_enabler = enable_if_t<is_detected<sub_t, U>::value,
int>;
458 template <
typename U = container_type, add_enabler<U> = 0>
477 template <
typename U = container_type, sub_enabler<U> = 0>
511 vector_key_merge_symbols(retval.m_container,
m_container, ins_map, args);
545 template <
typename T,
typename Derived,
typename S>
546 struct hash<
piranha::array_key<T, Derived, S>> {
Derived trim(const std::vector< char > &trim_mask, const symbol_fset &args) const
Trim.
const value_type & operator[](const size_type &i) const
Const element access.
const_iterator begin() const
Begin const iterator.
void push_back(const value_type &x)
Copy-add element at the end.
iterator begin()
Mutable begin iterator.
Equality-comparable type trait.
value_type & operator[](const size_type &i)
Element access.
container_type m_container
Internal container.
auto size_begin_end() -> decltype(m_container.size_begin_end())
Get size, begin and end iterator.
void push_back(const value_type &x)
Copy-add element at the end.
array_key(const symbol_fset &args)
Constructor from piranha::symbol_fset.
result_type operator()(const argument_type &a) const
Hash operator.
Type trait to detect the presence of the piranha::math::is_zero() function.
size_t result_type
Result type.
value_type const * const_iterator
Const iterator type.
bool operator!=(const array_key &other) const
Inequality operator.
array_key & operator=(const array_key &other)=default
Copy assignment operator.
size_type size() const
Size.
~array_key()
Trivial destructor.
array_key(const array_key< U, Derived2, S2 > &other, const symbol_fset &args)
Constructor from piranha::array_key parametrized on a generic type.
Derived merge_symbols(const symbol_idx_fmap< symbol_fset > &ins_map, const symbol_fset &args) const
Merge symbols.
bool operator==(const array_key &other) const
Equality operator.
#define piranha_throw(exception_type,...)
Exception-throwing macro.
iterator end()
Mutable end iterator.
boost::container::flat_set< std::string > symbol_fset
Flat set of symbols.
auto size_begin_end() const -> decltype(m_container.size_begin_end())
Get size, begin and end iterator (const version).
const_iterator end() const
End const iterator.
value_type * iterator
Iterator type.
array_key()=default
Defaulted default constructor.
typename container_type::iterator iterator
Iterator type.
typename container_type::size_type size_type
Size type.
bool is_zero(const T &x)
Zero test.
boost::container::flat_map< symbol_idx, T > symbol_idx_fmap
Flat map of symbol indices.
void resize(const size_type &size)
Resize.
typename container_type::value_type value_type
Value type.
typename container_type::const_iterator const_iterator
Const iterator type.
void vector_sub(array_key &retval, const array_key &other) const
Vector sub.
array_key(std::initializer_list< U > list)
Constructor from initializer list.
Less-than-comparable type trait.
std::size_t hash() const
Hash value.
piranha::array_key< T, Derived, S > argument_type
Argument type.
void vector_add(array_key &retval, const array_key &other) const
Vector add.
std::size_t hash() const
Hash method.
size_type_impl size_type
A fundamental unsigned integer type representing the number of elements stored in the vector...
iterator begin()
Begin iterator.
void push_back(value_type &&x)
Move-add element at the end.
Type trait for well-behaved container elements.
size_type size() const
Size.
std::tuple< size_type, iterator, iterator > size_begin_end()
Size, begin and end.
void trim_identify(std::vector< char > &trim_mask, const symbol_fset &args) const
Identify symbols that can be trimmed.
iterator end()
End iterator.
void sub(small_vector &retval, const small_vector &other) const
Vector subtraction.
safe_cast_type< To, From > safe_cast(const From &x)
Safe cast.
void resize(const size_type &new_size)
Resize the internal array container.
void add(small_vector &retval, const small_vector &other) const
Vector addition.