IAP GITLAB

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AirShowerPhysics/corsika
  • rulrich/corsika
  • AAAlvesJr/corsika
  • Andre/corsika
  • arrabito/corsika
  • Nikos/corsika
  • olheiser73/corsika
  • AirShowerPhysics/papers/corsika
  • pranav/corsika
9 results
Show changes
Showing
with 10212 additions and 215 deletions
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
/*
* Squares4.hpp
*
* Created on: 25/02/2021
* Author: Antonio Augusto Alves Junior
*/
#pragma once
#include <stdint.h>
#include "SquaresKeys.hpp"
namespace random_iterator {
namespace detail {
class Squares4_64 {
public:
typedef uint64_t init_type;
typedef uint64_t state_type;
typedef uint64_t seed_type;
typedef uint64_t advance_type;
typedef uint32_t result_type;
Squares4_64() = delete;
Squares4_64(seed_type s, uint32_t)
: state_(0)
, seed_(seed_type{splitmix<seed_type>(s)}) {}
Squares4_64(Squares4_64 const& other)
: state_(other.getState())
, seed_(other.getSeed()) {}
inline Squares4_64& operator=(Squares4_64 const& other) {
if (this == &other) return *this;
state_ = other.getState();
seed_ = other.getSeed();
return *this;
}
inline result_type operator()(void) {
uint64_t x, y, z;
y = x = seed_ * state_;
z = y + seed_;
x = x * x + y;
x = (x >> 32) | (x << 32); /* round 1 */
x = x * x + z;
x = (x >> 32) | (x << 32); /* round 2 */
x = x * x + y;
x = (x >> 32) | (x << 32); /* round 3 */
++state_; /* advance state */
return (x * x + z) >> 32; /* round 4 */
}
inline void reset(void) { state_ = 0; }
inline void discard(advance_type n) { state_ += n; }
inline seed_type getSeed() const { return seed_; }
inline void setSeed(seed_type seed) { seed_ = seed; }
inline state_type getState() const { return state_; }
inline void setState(state_type state) { state_ = state; }
inline static uint64_t generateSeed(size_t i) { return keys[i]; }
static constexpr result_type min() { return 0; }
static constexpr result_type max() {
return std::numeric_limits<result_type>::max();
}
friend inline std::ostream& operator<<(std::ostream& os, const Squares4_64& be) {
return os << "state: " << be.getState() << " seed: " << be.getSeed();
}
private:
state_type state_;
seed_type seed_;
};
} // namespace detail
} // namespace random_iterator
Source diff could not be displayed: it is too large. Options to address this: view the blob.
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
/*
* EngineCaller.hpp
*
* Created on: 23/02/2021
* Author: Antonio Augusto Alves Junior
*/
#pragma once
#include <stdint.h>
namespace random_iterator {
namespace detail {
template <typename DistibutionType, typename EngineType>
struct EngineCaller {
typedef EngineType engine_type;
typedef typename engine_type::state_type state_type;
typedef typename engine_type::seed_type seed_type;
typedef typename engine_type::advance_type advance_type;
typedef typename engine_type::init_type init_type;
typedef DistibutionType distribution_type;
typedef typename distribution_type::result_type result_type;
EngineCaller() = delete;
EngineCaller(distribution_type const& dist, seed_type seed, uint32_t stream)
: distribution_(dist)
, seed_(seed)
, stream_(stream) {}
EngineCaller(EngineCaller<DistibutionType, EngineType> const& other)
: distribution_(other.distribution_)
, seed_(other.seed_)
, stream_(other.stream_) {}
EngineCaller<DistibutionType, EngineType>& operator=(
EngineCaller<DistibutionType, EngineType> const& other) {
if (this == &other) return *this;
distribution_ = other.distribution_;
seed_ = other.seed_;
stream_ = other.stream_;
return *this;
}
inline result_type operator()(advance_type n) const {
EngineType eng(seed_, stream_);
eng.discard(n);
return static_cast<distribution_type>(distribution_)(eng);
}
distribution_type distribution_;
seed_type seed_;
uint32_t stream_;
};
} // namespace detail
} // namespace random_iterator
/*----------------------------------------------------------------------------
*
* Copyright (C) 2021 - 2024 Antonio Augusto Alves Junior
*
* This file is part of RandomIterator.
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ----------------------------------------------------------------------------*/
/*
* mulhilo64.h
*
* Created on: 12/03/2021
* Author: Antonio Augusto Alves Junior
*/
#pragma once
#include <cmath>
#include <cstdint>
#ifdef __powerpc64__
static inline uint64_t _mulhilo_asm_64(uint64_t ax, uint64_t b, uint64_t *hip){
uint64_t dx;
__asm__("\n\t"
"mulhdu" " %2\n\t"
: "=a"(ax), "=d"(dx)
: "r"(b), "0"(ax)
);
*hip = dx;
return ax;
}
#else
static inline uint64_t _mulhilo_asm_64(uint64_t ax, uint64_t b, uint64_t *hip){
uint64_t dx;
__asm__("\n\t"
"mulq" " %2\n\t"
: "=a"(ax), "=d"(dx)
: "r"(b), "0"(ax)
);
*hip = dx;
return ax;
}
#endif /* __powerpc64__ */
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __RANDOM_ITERATOR_TBB_tbb_windef_H
#error Do not #include this internal file directly; use public TBB headers instead.
#endif /* __RANDOM_ITERATOR_TBB_tbb_windef_H */
// Check that the target Windows version has all API calls required for TBB.
// Do not increase the version in condition beyond 0x0500 without prior discussion!
#if defined(_WIN32_WINNT) && _WIN32_WINNT<0x0501
#error TBB is unable to run on old Windows versions; _WIN32_WINNT must be 0x0501 or greater.
#endif
#if !defined(_MT)
#error TBB requires linkage with multithreaded C/C++ runtime library. \
Choose multithreaded DLL runtime in project settings, or use /MD[d] compiler switch.
#endif
// Workaround for the problem with MVSC headers failing to define namespace std
namespace std {
using ::size_t; using ::ptrdiff_t;
}
#define __RANDOM_ITERATOR_TBB_STRING_AUX(x) #x
#define __RANDOM_ITERATOR_TBB_STRING(x) __RANDOM_ITERATOR_TBB_STRING_AUX(x)
// Default setting of RANDOM_ITERATOR_TBB_USE_DEBUG
#ifdef RANDOM_ITERATOR_TBB_USE_DEBUG
# if RANDOM_ITERATOR_TBB_USE_DEBUG
# if !defined(_DEBUG)
# pragma message(__FILE__ "(" __RANDOM_ITERATOR_TBB_STRING(__LINE__) ") : Warning: Recommend using /MDd if compiling with RANDOM_ITERATOR_TBB_USE_DEBUG!=0")
# endif
# else
# if defined(_DEBUG)
# pragma message(__FILE__ "(" __RANDOM_ITERATOR_TBB_STRING(__LINE__) ") : Warning: Recommend using /MD if compiling with RANDOM_ITERATOR_TBB_USE_DEBUG==0")
# endif
# endif
#endif
#if (__RANDOM_ITERATOR_TBB_BUILD || __RANDOM_ITERATOR_TBBMALLOC_BUILD || __RANDOM_ITERATOR_TBBBIND_BUILD) && !defined(__RANDOM_ITERATOR_TBB_NO_IMPLICIT_LINKAGE)
#define __RANDOM_ITERATOR_TBB_NO_IMPLICIT_LINKAGE 1
#endif
#if _MSC_VER
#if !__RANDOM_ITERATOR_TBB_NO_IMPLICIT_LINKAGE
#ifdef __RANDOM_ITERATOR_TBB_LIB_NAME
#pragma comment(lib, __RANDOM_ITERATOR_TBB_STRING(__RANDOM_ITERATOR_TBB_LIB_NAME))
#else
#ifdef _DEBUG
#pragma comment(lib, "tbb_debug.lib")
#else
#pragma comment(lib, "tbb.lib")
#endif
#endif
#endif
#endif
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __RANDOM_ITERATOR_TBB_template_helpers_H
#define __RANDOM_ITERATOR_TBB_template_helpers_H
#include <utility>
#include <cstddef>
#include "../tbb_config.h"
#if __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT
#include <type_traits>
#endif
#if __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#include <iterator>
#include <memory> // allocator_traits
#endif
namespace random_iterator_tbb { namespace internal {
//! Enables one or the other code branches
template<bool Condition, typename T = void> struct enable_if {};
template<typename T> struct enable_if<true, T> { typedef T type; };
//! Strips its template type argument from cv- and ref-qualifiers
template<typename T> struct strip { typedef T type; };
template<typename T> struct strip<const T> { typedef T type; };
template<typename T> struct strip<volatile T> { typedef T type; };
template<typename T> struct strip<const volatile T> { typedef T type; };
template<typename T> struct strip<T&> { typedef T type; };
template<typename T> struct strip<const T&> { typedef T type; };
template<typename T> struct strip<volatile T&> { typedef T type; };
template<typename T> struct strip<const volatile T&> { typedef T type; };
//! Specialization for function pointers
template<typename T> struct strip<T(&)()> { typedef T(*type)(); };
#if __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT
template<typename T> struct strip<T&&> { typedef T type; };
template<typename T> struct strip<const T&&> { typedef T type; };
template<typename T> struct strip<volatile T&&> { typedef T type; };
template<typename T> struct strip<const volatile T&&> { typedef T type; };
#endif
//! Specialization for arrays converts to a corresponding pointer
template<typename T, std::size_t N> struct strip<T(&)[N]> { typedef T* type; };
template<typename T, std::size_t N> struct strip<const T(&)[N]> { typedef const T* type; };
template<typename T, std::size_t N> struct strip<volatile T(&)[N]> { typedef volatile T* type; };
template<typename T, std::size_t N> struct strip<const volatile T(&)[N]> { typedef const volatile T* type; };
//! Detects whether two given types are the same
template<class U, class V> struct is_same_type { static const bool value = false; };
template<class W> struct is_same_type<W,W> { static const bool value = true; };
template<typename T> struct is_ref { static const bool value = false; };
template<typename U> struct is_ref<U&> { static const bool value = true; };
//! Partial support for std::is_integral
template<typename T> struct is_integral_impl { static const bool value = false; };
template<> struct is_integral_impl<bool> { static const bool value = true; };
template<> struct is_integral_impl<char> { static const bool value = true; };
#if __RANDOM_ITERATOR_TBB_CPP11_PRESENT
template<> struct is_integral_impl<char16_t> { static const bool value = true; };
template<> struct is_integral_impl<char32_t> { static const bool value = true; };
#endif
template<> struct is_integral_impl<wchar_t> { static const bool value = true; };
template<> struct is_integral_impl<short> { static const bool value = true; };
template<> struct is_integral_impl<int> { static const bool value = true; };
template<> struct is_integral_impl<long> { static const bool value = true; };
template<> struct is_integral_impl<long long> { static const bool value = true; };
template<typename T>
struct is_integral : is_integral_impl<typename strip<T>::type> {};
#if __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
//! std::void_t internal implementation (to avoid GCC < 4.7 "template aliases" absence)
template<typename...> struct void_t { typedef void type; };
#endif
#if __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT
// Generic SFINAE helper for expression checks, based on the idea demonstrated in ISO C++ paper n4502
template<typename T, typename, template<typename> class... Checks>
struct supports_impl { typedef std::false_type type; };
template<typename T, template<typename> class... Checks>
struct supports_impl<T, typename void_t<Checks<T>...>::type, Checks...> { typedef std::true_type type; };
template<typename T, template<typename> class... Checks>
using supports = typename supports_impl<T, void, Checks...>::type;
#endif /* __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT */
#if __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
//! Allows to store a function parameter pack as a variable and later pass it to another function
template< typename... Types >
struct stored_pack;
template<>
struct stored_pack<>
{
typedef stored_pack<> pack_type;
stored_pack() {}
// Friend front-end functions
template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
protected:
// Ideally, ref-qualified non-static methods would be used,
// but that would greatly reduce the set of compilers where it works.
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, const pack_type& /*pack*/, Preceding&&... params ) {
return std::forward<F>(f)( std::forward<Preceding>(params)... );
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type&& /*pack*/, Preceding&&... params ) {
return std::forward<F>(f)( std::forward<Preceding>(params)... );
}
};
template< typename T, typename... Types >
struct stored_pack<T, Types...> : stored_pack<Types...>
{
typedef stored_pack<T, Types...> pack_type;
typedef stored_pack<Types...> pack_remainder;
// Since lifetime of original values is out of control, copies should be made.
// Thus references should be stripped away from the deduced type.
typename strip<T>::type leftmost_value;
// Here rvalue references act in the same way as forwarding references,
// as long as class template parameters were deduced via forwarding references.
stored_pack( T&& t, Types&&... types )
: pack_remainder(std::forward<Types>(types)...), leftmost_value(std::forward<T>(t)) {}
// Friend front-end functions
template< typename F, typename Pack > friend void call( F&& f, Pack&& p );
template< typename Ret, typename F, typename Pack > friend Ret call_and_return( F&& f, Pack&& p );
protected:
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<pack_remainder&>(pack),
std::forward<Preceding>(params)... , pack.leftmost_value
);
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, const pack_type& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<const pack_remainder&>(pack),
std::forward<Preceding>(params)... , pack.leftmost_value
);
}
template< typename Ret, typename F, typename... Preceding >
static Ret call( F&& f, pack_type&& pack, Preceding&&... params ) {
return pack_remainder::template call<Ret>(
std::forward<F>(f), static_cast<pack_remainder&&>(pack),
std::forward<Preceding>(params)... , std::move(pack.leftmost_value)
);
}
};
//! Calls the given function with arguments taken from a stored_pack
template< typename F, typename Pack >
void call( F&& f, Pack&& p ) {
strip<Pack>::type::template call<void>( std::forward<F>(f), std::forward<Pack>(p) );
}
template< typename Ret, typename F, typename Pack >
Ret call_and_return( F&& f, Pack&& p ) {
return strip<Pack>::type::template call<Ret>( std::forward<F>(f), std::forward<Pack>(p) );
}
template< typename... Types >
stored_pack<Types...> save_pack( Types&&... types ) {
return stored_pack<Types...>( std::forward<Types>(types)... );
}
#endif /* __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
#if __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT
using std::index_sequence;
using std::make_index_sequence;
#elif __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT
template<std::size_t... S> class index_sequence {};
template<std::size_t N, std::size_t... S>
struct make_index_sequence_impl : make_index_sequence_impl < N - 1, N - 1, S... > {};
template<std::size_t... S>
struct make_index_sequence_impl <0, S...> {
using type = index_sequence<S...>;
};
template<std::size_t N>
using make_index_sequence = typename tbb::internal::make_index_sequence_impl<N>::type;
#endif /* __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT */
#if __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
template<typename... Args>
struct conjunction;
template<typename First, typename... Args>
struct conjunction<First, Args...>
: std::conditional<bool(First::value), conjunction<Args...>, First>::type {};
template<typename T>
struct conjunction<T> : T {};
template<>
struct conjunction<> : std::true_type {};
#endif
#if __RANDOM_ITERATOR_TBB_CPP11_PRESENT
template< typename Iter >
using iterator_value_t = typename std::iterator_traits<Iter>::value_type;
template< typename Iter >
using iterator_key_t = typename std::remove_const<typename iterator_value_t<Iter>::first_type>::type;
template< typename Iter >
using iterator_mapped_t = typename iterator_value_t<Iter>::second_type;
template< typename A > using value_type = typename A::value_type;
template< typename A > using alloc_ptr_t = typename std::allocator_traits<A>::pointer;
template< typename A > using has_allocate = decltype(std::declval<alloc_ptr_t<A>&>() = std::declval<A>().allocate(0));
template< typename A > using has_deallocate = decltype(std::declval<A>().deallocate(std::declval<alloc_ptr_t<A>>(), 0));
// value_type should be checked first because it can be used in other checks (via allocator_traits)
template< typename T >
using is_allocator = supports<T, value_type, has_allocate, has_deallocate>;
#if __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT
template< typename T >
static constexpr bool is_allocator_v = is_allocator<T>::value;
#endif /*__RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES */
template< std::size_t N, typename... Args >
struct pack_element {
using type = void;
};
template< std::size_t N, typename T, typename... Args >
struct pack_element<N, T, Args...> {
using type = typename pack_element<N - 1, Args...>::type;
};
template< typename T, typename... Args >
struct pack_element<0, T, Args...> {
using type = T;
};
template< std::size_t N, typename... Args >
using pack_element_t = typename pack_element<N, Args...>::type;
// Helper alias for heterogeneous lookup functions in containers
// template parameter K and std::conditional are needed to provide immediate context
// and postpone getting is_trasparent from the compare functor until method instantiation.
template <typename Comp, typename K>
using is_transparent = typename std::conditional<true, Comp, K>::type::is_transparent;
#endif /* __RANDOM_ITERATOR_TBB_CPP11_PRESENT */
template <typename F>
struct body_arg_detector;
template <typename Callable, typename ReturnType, typename T>
struct body_arg_detector<ReturnType(Callable::*)(T)> {
typedef T arg_type;
};
template <typename Callable, typename ReturnType, typename T>
struct body_arg_detector<ReturnType(Callable::*)(T) const> {
typedef T arg_type;
};
#if __RANDOM_ITERATOR_TBB_CPP11_PRESENT
using std::conditional;
#else
template <bool C, typename T, typename U>
struct conditional {
typedef U type;
};
template <typename T, typename U>
struct conditional<true, T, U> {
typedef T type;
};
#endif
} } // namespace internal, namespace random_iterator_tbb
#endif /* __RANDOM_ITERATOR_TBB_template_helpers_H */
/*
Copyright (c) 2017-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __RANDOM_ITERATOR_TBB_iterators_H
#define __RANDOM_ITERATOR_TBB_iterators_H
#include <iterator>
#include <limits>
#include "tbb_config.h"
#include "tbb_stddef.h"
#if __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#include <type_traits>
namespace random_iterator_tbb {
template <typename Type>
class constant_iterator {
public:
typedef typename std::size_t difference_type;
typedef Type value_type;
typedef const Type* pointer;
typedef const Type& reference;
typedef std::random_access_iterator_tag iterator_category;
constant_iterator()
: my_value() {}
explicit constant_iterator(Type init)
: my_value(init) {}
inline reference operator*() const { return my_value; }
inline value_type operator[](difference_type) const { return my_value; }
inline difference_type operator-(const constant_iterator<Type>&) const { return 0; }
inline constant_iterator<Type>& operator+=(difference_type) const { return *this; }
inline constant_iterator<Type>& operator-=(difference_type) const { return *this; }
inline constant_iterator<Type>& operator++() const { return *this; }
inline constant_iterator<Type>& operator--() const { return *this; }
inline constant_iterator<Type> operator++(int) {
return constant_iterator<Type>(my_value);
}
inline constant_iterator<Type> operator--(int) {
return constant_iterator<Type>(my_value);
}
inline constant_iterator<Type> operator-(difference_type) const {
return constant_iterator<Type>(my_value);
}
inline constant_iterator<Type> operator+(difference_type) const {
return constant_iterator<Type>(my_value);
}
friend constant_iterator<Type> operator+(difference_type,
const constant_iterator<Type> it) {
return constant_iterator<Type>(*it);
}
inline bool operator==(const constant_iterator<Type>& it) const {
return (my_value - *it) == 0;
}
inline bool operator!=(const constant_iterator<Type>& it) const {
return !(my_value == *it);
}
private:
const value_type my_value;
};
template <typename IntType>
class counting_iterator {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(
std::numeric_limits<IntType>::is_integer,
"Cannot instantiate counting_iterator with a non-integer type");
public:
typedef typename std::make_signed<IntType>::type difference_type;
typedef IntType value_type;
typedef const IntType* pointer;
typedef const IntType& reference;
typedef std::random_access_iterator_tag iterator_category;
counting_iterator()
: my_counter() {}
explicit counting_iterator(IntType init)
: my_counter(init) {}
inline reference operator*() const { return my_counter; }
inline value_type operator[](difference_type i) const { return *(*this + i); }
inline difference_type operator-(const counting_iterator& it) const {
return my_counter - it.my_counter;
}
inline counting_iterator& operator+=(difference_type forward) {
my_counter += forward;
return *this;
}
inline counting_iterator& operator-=(difference_type backward) {
return *this += -backward;
}
inline counting_iterator& operator++() { return *this += 1; }
inline counting_iterator& operator--() { return *this -= 1; }
inline counting_iterator operator++(int) {
counting_iterator it(*this);
++(*this);
return it;
}
inline counting_iterator operator--(int) {
counting_iterator it(*this);
--(*this);
return it;
}
inline counting_iterator operator-(difference_type backward) const {
return counting_iterator(my_counter - backward);
}
inline counting_iterator operator+(difference_type forward) const {
return counting_iterator(my_counter + forward);
}
friend counting_iterator operator+(difference_type forward,
const counting_iterator it) {
return it + forward;
}
inline bool operator==(const counting_iterator& it) const { return *this - it == 0; }
inline bool operator!=(const counting_iterator& it) const { return !(*this == it); }
inline bool operator<(const counting_iterator& it) const { return *this - it < 0; }
inline bool operator>(const counting_iterator& it) const { return it < *this; }
inline bool operator<=(const counting_iterator& it) const { return !(*this > it); }
inline bool operator>=(const counting_iterator& it) const { return !(*this < it); }
private:
IntType my_counter;
};
} // namespace random_iterator_tbb
#include <tuple>
#include "internal/_template_helpers.h" // index_sequence, make_index_sequence
namespace random_iterator_tbb {
namespace internal {
template <size_t N>
struct tuple_util {
template <typename TupleType, typename DifferenceType>
static void increment(TupleType& it, DifferenceType forward) {
std::get<N - 1>(it) += forward;
tuple_util<N - 1>::increment(it, forward);
}
template <typename TupleType, typename DifferenceType>
static bool check_sync(const TupleType& it1, const TupleType& it2,
DifferenceType val) {
if (std::get<N - 1>(it1) - std::get<N - 1>(it2) != val) return false;
return tuple_util<N - 1>::check_sync(it1, it2, val);
}
};
template <>
struct tuple_util<0> {
template <typename TupleType, typename DifferenceType>
static void increment(TupleType&, DifferenceType) {}
template <typename TupleType, typename DifferenceType>
static bool check_sync(const TupleType&, const TupleType&, DifferenceType) {
return true;
}
};
template <typename TupleReturnType>
struct make_references {
template <typename TupleType, std::size_t... Is>
TupleReturnType operator()(const TupleType& t,
random_iterator_tbb::internal::index_sequence<Is...>) {
return std::tie(*std::get<Is>(t)...);
}
};
// A simple wrapper over a tuple of references.
// The class is designed to hold a temporary tuple of reference
// after dereferencing a zip_iterator; in particular, it is needed
// to swap these rvalue tuples. Any other usage is not supported.
template <typename... T>
struct tuplewrapper
: public std::tuple<
typename std::enable_if<std::is_reference<T>::value, T&&>::type...> {
// In the context of this class, T is a reference, so T&& is a "forwarding
// reference"
typedef std::tuple<T&&...> base_type;
// Construct from the result of std::tie
tuplewrapper(const base_type& in)
: base_type(in) {}
#if __INTEL_COMPILER
// ICC cannot generate copy ctor & assignment
tuplewrapper(const tuplewrapper& rhs)
: base_type(rhs) {}
tuplewrapper& operator=(const tuplewrapper& rhs) {
*this = base_type(rhs);
return *this;
}
#endif
// Assign any tuple convertible to std::tuple<T&&...>: *it = a_tuple;
template <typename... U>
tuplewrapper& operator=(const std::tuple<U...>& other) {
base_type::operator=(other);
return *this;
}
#if _LIBCPP_VERSION
// (Necessary for libc++ tuples) Convert to a tuple of values: v = *it;
operator std::tuple<typename std::remove_reference<T>::type...>() {
return base_type(*this);
}
#endif
// Swap rvalue tuples: swap(*it1,*it2);
friend void swap(tuplewrapper&& a, tuplewrapper&& b) { std::swap<T&&...>(a, b); }
};
} // namespace internal
template <typename... Types>
class zip_iterator {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(
sizeof...(Types) > 0,
"Cannot instantiate zip_iterator with empty template parameter pack");
static const std::size_t num_types = sizeof...(Types);
typedef std::tuple<Types...> it_types;
public:
typedef typename std::make_signed<std::size_t>::type difference_type;
typedef std::tuple<typename std::iterator_traits<Types>::value_type...> value_type;
#if __INTEL_COMPILER && __INTEL_COMPILER < 1800 && _MSC_VER
typedef std::tuple<typename std::iterator_traits<Types>::reference...> reference;
#else
typedef random_iterator_tbb::internal::tuplewrapper<
typename std::iterator_traits<Types>::reference...>
reference;
#endif
typedef std::tuple<typename std::iterator_traits<Types>::pointer...> pointer;
typedef std::random_access_iterator_tag iterator_category;
zip_iterator()
: my_it() {}
explicit zip_iterator(Types... args)
: my_it(std::make_tuple(args...)) {}
zip_iterator(const zip_iterator& input)
: my_it(input.my_it) {}
zip_iterator& operator=(const zip_iterator& input) {
my_it = input.my_it;
return *this;
}
reference operator*() const {
return random_iterator_tbb::internal::make_references<reference>()(
my_it, random_iterator_tbb::internal::make_index_sequence<num_types>());
}
reference operator[](difference_type i) const { return *(*this + i); }
difference_type operator-(const zip_iterator& it) const {
__RANDOM_ITERATOR_TBB_ASSERT(
internal::tuple_util<num_types>::check_sync(
my_it, it.my_it, std::get<0>(my_it) - std::get<0>(it.my_it)),
"Components of zip_iterator are not synchronous");
return std::get<0>(my_it) - std::get<0>(it.my_it);
}
zip_iterator& operator+=(difference_type forward) {
internal::tuple_util<num_types>::increment(my_it, forward);
return *this;
}
zip_iterator& operator-=(difference_type backward) { return *this += -backward; }
zip_iterator& operator++() { return *this += 1; }
zip_iterator& operator--() { return *this -= 1; }
zip_iterator operator++(int) {
zip_iterator it(*this);
++(*this);
return it;
}
zip_iterator operator--(int) {
zip_iterator it(*this);
--(*this);
return it;
}
zip_iterator operator-(difference_type backward) const {
zip_iterator it(*this);
return it -= backward;
}
zip_iterator operator+(difference_type forward) const {
zip_iterator it(*this);
return it += forward;
}
friend zip_iterator operator+(difference_type forward, const zip_iterator& it) {
return it + forward;
}
bool operator==(const zip_iterator& it) const { return *this - it == 0; }
it_types base() const { return my_it; }
bool operator!=(const zip_iterator& it) const { return !(*this == it); }
bool operator<(const zip_iterator& it) const { return *this - it < 0; }
bool operator>(const zip_iterator& it) const { return it < *this; }
bool operator<=(const zip_iterator& it) const { return !(*this > it); }
bool operator>=(const zip_iterator& it) const { return !(*this < it); }
private:
it_types my_it;
};
template <typename... T>
zip_iterator<T...> make_zip_iterator(T... args) {
return zip_iterator<T...>(args...);
}
template <typename UnaryFunc, typename Iter>
class transform_iterator {
public:
typedef typename std::iterator_traits<Iter>::value_type value_type;
typedef typename std::iterator_traits<Iter>::difference_type difference_type;
#if __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT
typedef typename std::invoke_result<
UnaryFunc, typename std::iterator_traits<Iter>::reference>::type reference;
#else
typedef typename std::result_of<UnaryFunc(
typename std::iterator_traits<Iter>::reference)>::type reference;
#endif
typedef typename std::iterator_traits<Iter>::pointer pointer;
typedef typename std::random_access_iterator_tag iterator_category;
transform_iterator(Iter it, UnaryFunc unary_func)
: my_it(it)
, my_unary_func(unary_func) {
__RANDOM_ITERATOR_TBB_STATIC_ASSERT(
(std::is_same<typename std::iterator_traits<Iter>::iterator_category,
std::random_access_iterator_tag>::value),
"Random access iterator required.");
}
transform_iterator(const transform_iterator& input)
: my_it(input.my_it)
, my_unary_func(input.my_unary_func) {}
transform_iterator& operator=(const transform_iterator& input) {
my_it = input.my_it;
return *this;
}
reference operator*() const { return my_unary_func(*my_it); }
reference operator[](difference_type i) const { return *(*this + i); }
transform_iterator& operator++() {
++my_it;
return *this;
}
transform_iterator& operator--() {
--my_it;
return *this;
}
transform_iterator operator++(int) {
transform_iterator it(*this);
++(*this);
return it;
}
transform_iterator operator--(int) {
transform_iterator it(*this);
--(*this);
return it;
}
transform_iterator operator+(difference_type forward) const {
return {my_it + forward, my_unary_func};
}
transform_iterator operator-(difference_type backward) const {
return {my_it - backward, my_unary_func};
}
transform_iterator& operator+=(difference_type forward) {
my_it += forward;
return *this;
}
transform_iterator& operator-=(difference_type backward) {
my_it -= backward;
return *this;
}
friend transform_iterator operator+(difference_type forward,
const transform_iterator& it) {
return it + forward;
}
difference_type operator-(const transform_iterator& it) const {
return my_it - it.my_it;
}
bool operator==(const transform_iterator& it) const { return *this - it == 0; }
bool operator!=(const transform_iterator& it) const { return !(*this == it); }
bool operator<(const transform_iterator& it) const { return *this - it < 0; }
bool operator>(const transform_iterator& it) const { return it < *this; }
bool operator<=(const transform_iterator& it) const { return !(*this > it); }
bool operator>=(const transform_iterator& it) const { return !(*this < it); }
Iter base() const { return my_it; }
private:
Iter my_it;
const UnaryFunc my_unary_func;
};
template <typename UnaryFunc, typename Iter>
transform_iterator<UnaryFunc, Iter> make_transform_iterator(Iter it,
UnaryFunc unary_func) {
return transform_iterator<UnaryFunc, Iter>(it, unary_func);
}
} // namespace random_iterator_tbb
#endif //__RANDOM_ITERATOR_TBB_CPP11_PRESENT
#endif /* __RANDOM_ITERATOR_TBB_iterators_H */
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __RANDOM_ITERATOR_TBB_tbb_config_H
#define __RANDOM_ITERATOR_TBB_tbb_config_H
/** This header is supposed to contain macro definitions and C style comments only.
The macros defined here are intended to control such aspects of TBB build as
- presence of compiler features
- compilation modes
- feature sets
- known compiler/platform issues
**/
/* This macro marks incomplete code or comments describing ideas which are considered for the future.
* See also for plain comment with TODO and FIXME marks for small improvement opportunities.
*/
#define __RANDOM_ITERATOR_TBB_TODO 0
/* Check which standard library we use. */
/* __RANDOM_ITERATOR_TBB_SYMBOL is defined only while processing exported symbols list where C++ is not allowed. */
#if !defined(__RANDOM_ITERATOR_TBB_SYMBOL) && !__RANDOM_ITERATOR_TBB_CONFIG_PREPROC_ONLY
#include <cstddef>
#endif
// Note that when ICC or Clang is in use, __RANDOM_ITERATOR_TBB_GCC_VERSION might not fully match
// the actual GCC version on the system.
#define __RANDOM_ITERATOR_TBB_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
// Prior to GCC 7, GNU libstdc++ did not have a convenient version macro.
// Therefore we use different ways to detect its version.
#if defined(RANDOM_ITERATOR_TBB_USE_GLIBCXX_VERSION) && !defined(_GLIBCXX_RELEASE)
// The version is explicitly specified in our public RANDOM_ITERATOR_TBB_USE_GLIBCXX_VERSION macro.
// Its format should match the __RANDOM_ITERATOR_TBB_GCC_VERSION above, e.g. 70301 for libstdc++ coming with GCC 7.3.1.
#define __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION RANDOM_ITERATOR_TBB_USE_GLIBCXX_VERSION
#elif _GLIBCXX_RELEASE && _GLIBCXX_RELEASE != __GNUC__
// Reported versions of GCC and libstdc++ do not match; trust the latter
#define __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION (_GLIBCXX_RELEASE*10000)
#elif __GLIBCPP__ || __GLIBCXX__
// The version macro is not defined or matches the GCC version; use __RANDOM_ITERATOR_TBB_GCC_VERSION
#define __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION __RANDOM_ITERATOR_TBB_GCC_VERSION
#endif
#if __clang__
// according to clang documentation, version can be vendor specific
#define __RANDOM_ITERATOR_TBB_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
#endif
/** Target OS is either iOS* or iOS* simulator **/
#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__
#define __RANDOM_ITERATOR_TBB_IOS 1
#endif
#if __APPLE__
#if __INTEL_COMPILER && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ > 1099 \
&& __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101000
// ICC does not correctly set the macro if -mmacosx-min-version is not specified
#define __RANDOM_ITERATOR_TBB_MACOS_TARGET_VERSION (100000 + 10*(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 1000))
#else
#define __RANDOM_ITERATOR_TBB_MACOS_TARGET_VERSION __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
#endif
#endif
/** Preprocessor symbols to determine HW architecture **/
#if _WIN32||_WIN64
# if defined(_M_X64)||defined(__x86_64__) // the latter for MinGW support
# define __RANDOM_ITERATOR_TBB_x86_64 1
# elif defined(_M_IA64)
# define __RANDOM_ITERATOR_TBB_ipf 1
# elif defined(_M_IX86)||defined(__i386__) // the latter for MinGW support
# define __RANDOM_ITERATOR_TBB_x86_32 1
# else
# define __RANDOM_ITERATOR_TBB_generic_arch 1
# endif
#else /* Assume generic Unix */
# if !__linux__ && !__APPLE__
# define __RANDOM_ITERATOR_TBB_generic_os 1
# endif
# if __RANDOM_ITERATOR_TBB_IOS
# define __RANDOM_ITERATOR_TBB_generic_arch 1
# elif __x86_64__
# define __RANDOM_ITERATOR_TBB_x86_64 1
# elif __ia64__
# define __RANDOM_ITERATOR_TBB_ipf 1
# elif __i386__||__i386 // __i386 is for Sun OS
# define __RANDOM_ITERATOR_TBB_x86_32 1
# else
# define __RANDOM_ITERATOR_TBB_generic_arch 1
# endif
#endif
#if __MIC__ || __MIC2__
#define __RANDOM_ITERATOR_TBB_DEFINE_MIC 1
#endif
#define __RANDOM_ITERATOR_TBB_TSX_AVAILABLE ((__RANDOM_ITERATOR_TBB_x86_32 || __RANDOM_ITERATOR_TBB_x86_64) && !__RANDOM_ITERATOR_TBB_DEFINE_MIC)
/** Presence of compiler features **/
#if __INTEL_COMPILER == 9999 && __INTEL_COMPILER_BUILD_DATE == 20110811
/* Intel(R) Composer XE 2011 Update 6 incorrectly sets __INTEL_COMPILER. Fix it. */
#undef __INTEL_COMPILER
#define __INTEL_COMPILER 1210
#endif
#if __clang__ && !__INTEL_COMPILER
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_OPTIONAL_RTTI __has_feature(cxx_rtti)
#elif defined(_CPPRTTI)
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_OPTIONAL_RTTI 1
#else
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_OPTIONAL_RTTI (__GXX_RTTI || __RTTI || __INTEL_RTTI__)
#endif
#if __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400 && !defined(__INTEL_COMPILER)
/** warning suppression pragmas available in GCC since 4.4 **/
#define __RANDOM_ITERATOR_TBB_GCC_WARNING_SUPPRESSION_PRESENT 1
#endif
/* Select particular features of C++11 based on compiler version.
ICC 12.1 (Linux*), GCC 4.3 and higher, clang 2.9 and higher
set __GXX_EXPERIMENTAL_CXX0X__ in c++11 mode.
Compilers that mimics other compilers (ICC, clang) must be processed before
compilers they mimic (GCC, MSVC).
TODO: The following conditions should be extended when new compilers/runtimes
support added.
*/
/**
__RANDOM_ITERATOR_TBB_CPP11_PRESENT macro indicates that the compiler supports vast majority of C++11 features.
Depending on the compiler, some features might still be unsupported or work incorrectly.
Use it when enabling C++11 features individually is not practical, and be aware that
some "good enough" compilers might be excluded. **/
#define __RANDOM_ITERATOR_TBB_CPP11_PRESENT (__cplusplus >= 201103L || _MSC_VER >= 1900)
#define __RANDOM_ITERATOR_TBB_CPP17_FALLTHROUGH_PRESENT (__cplusplus >= 201703L)
#define __RANDOM_ITERATOR_TBB_FALLTHROUGH_PRESENT (__RANDOM_ITERATOR_TBB_GCC_VERSION >= 70000 && !__INTEL_COMPILER)
/** C++11 mode detection macros for Intel(R) C++ Compiler (enabled by -std=c++XY option):
__INTEL_CXX11_MODE__ for version >=13.0 (not available for ICC 15.0 if -std=c++14 is used),
__STDC_HOSTED__ for version >=12.0 (useful only on Windows),
__GXX_EXPERIMENTAL_CXX0X__ for version >=12.0 on Linux and macOS. **/
#if __INTEL_COMPILER && !__INTEL_CXX11_MODE__
// __INTEL_CXX11_MODE__ is not set, try to deduce it
#define __INTEL_CXX11_MODE__ (__GXX_EXPERIMENTAL_CXX0X__ || (_MSC_VER && __STDC_HOSTED__))
#endif
#if __INTEL_COMPILER && (!_MSC_VER || __INTEL_CXX11_MODE__)
// On Windows, C++11 features supported by Visual Studio 2010 and higher are enabled by default,
// so in absence of /Qstd= use MSVC branch for feature detection.
// On other platforms, no -std= means C++03.
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT (__INTEL_CXX11_MODE__ && __VARIADIC_TEMPLATES)
// Both r-value reference support in compiler and std::move/std::forward
// presence in C++ standard library is checked.
#define __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT ((_MSC_VER >= 1700 || __GXX_EXPERIMENTAL_CXX0X__ && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40500 || _LIBCPP_VERSION)) && __INTEL_COMPILER >= 1400)
#define __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1400 && (_MSC_VER >= 1900 || __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40600 || __clang__))
#if _MSC_VER >= 1600
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT ( __INTEL_COMPILER > 1300 \
/*ICC 12.1 Upd 10 and 13 beta Upd 2 fixed exception_ptr linking issue*/ \
|| (__INTEL_COMPILER == 1300 && __INTEL_COMPILER_BUILD_DATE >= 20120530) \
|| (__INTEL_COMPILER == 1210 && __INTEL_COMPILER_BUILD_DATE >= 20120410) )
/** libstdc++ that comes with GCC 4.6 use C++11 features not supported by ICC 12.1.
* Because of that ICC 12.1 does not support C++11 mode with gcc 4.6 (or higher),
* and therefore does not define __GXX_EXPERIMENTAL_CXX0X__ macro **/
#elif __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40404 && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION < 40600
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1200)
#elif __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1300)
#elif _LIBCPP_VERSION
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT __GXX_EXPERIMENTAL_CXX0X__
#else
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT 0
#endif
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT (__INTEL_CXX11_MODE__ || _MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_CPP11_TUPLE_PRESENT (_MSC_VER >= 1600 || __GXX_EXPERIMENTAL_CXX0X__ && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40300 || _LIBCPP_VERSION))
#define __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1400 && (_MSC_VER >= 1800 || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40400 || _LIBCPP_VERSION))
#define __RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1400)
#define __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1200)
/** ICC seems to disable support of noexcept event in c++11 when compiling in compatibility mode for gcc <4.6 **/
#define __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1300 && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600 || _LIBCPP_VERSION || _MSC_VER))
#define __RANDOM_ITERATOR_TBB_CPP11_STD_BEGIN_END_PRESENT (_MSC_VER >= 1700 || __GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1310 && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600 || _LIBCPP_VERSION))
#define __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT (_MSC_VER >= 1600 || __GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1210)
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT (_MSC_VER >= 1600 || __GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1210)
#define __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1200)
#define __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT (_MSC_VER >= 1800 || __GXX_EXPERIMENTAL_CXX0X__ && __INTEL_COMPILER >= 1210)
#define __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1400)
#define __RANDOM_ITERATOR_TBB_ALIGNAS_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1500)
#define __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT (__INTEL_CXX11_MODE__ && __INTEL_COMPILER >= 1210)
#define __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__INTEL_COMPILER > 1910) // a future version
#define __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT (__cplusplus >= 201703L)
#elif __clang__
/** TODO: these options need to be rechecked **/
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT __has_feature(__cxx_variadic_templates__)
#define __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT (__has_feature(__cxx_rvalue_references__) && (_LIBCPP_VERSION || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40500))
#define __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT __has_feature(cxx_implicit_moves)
/** TODO: extend exception_ptr related conditions to cover libstdc++ **/
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT (__cplusplus >= 201103L && (_LIBCPP_VERSION || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600))
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT __has_feature(__cxx_static_assert__)
#if (__cplusplus >= 201103L && __has_include(<tuple>))
#define __RANDOM_ITERATOR_TBB_CPP11_TUPLE_PRESENT 1
#endif
#if (__has_feature(__cxx_generalized_initializers__) && __has_include(<initializer_list>))
#define __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT 1
#endif
#define __RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT __has_feature(__cxx_constexpr__)
#define __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT (__has_feature(__cxx_defaulted_functions__) && __has_feature(__cxx_deleted_functions__))
/**For some unknown reason __has_feature(__cxx_noexcept) does not yield true for all cases. Compiler bug ? **/
#define __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT (__cplusplus >= 201103L)
#define __RANDOM_ITERATOR_TBB_CPP11_STD_BEGIN_END_PRESENT (__has_feature(__cxx_range_for__) && (_LIBCPP_VERSION || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600))
#define __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT __has_feature(__cxx_auto_type__)
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT __has_feature(__cxx_decltype__)
#define __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT __has_feature(cxx_lambdas)
#define __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT __has_feature(cxx_default_function_template_args)
#define __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT __has_feature(cxx_override_control)
#define __RANDOM_ITERATOR_TBB_ALIGNAS_PRESENT __has_feature(cxx_alignas)
#define __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT __has_feature(cxx_alias_templates)
#define __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__has_feature(cxx_variable_templates))
#define __RANDOM_ITERATOR_TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__has_feature(__cpp_deduction_guides))
#define __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT (__has_feature(__cpp_lib_is_invocable))
#elif __GNUC__
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT __GXX_EXPERIMENTAL_CXX0X__
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_FIXED_LENGTH_EXP_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40700)
#define __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40500)
#define __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40600)
/** __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 here is a substitution for _GLIBCXX_ATOMIC_BUILTINS_4, which is a prerequisite
for exception_ptr but cannot be used in this file because it is defined in a header, not by the compiler.
If the compiler has no atomic intrinsics, the C++ library should not expect those as well. **/
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40404 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40300)
#define __RANDOM_ITERATOR_TBB_CPP11_TUPLE_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40300)
#define __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400)
/** gcc seems have to support constexpr from 4.4 but tests in (test_atomic) seeming reasonable fail to compile prior 4.6**/
#define __RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400)
#define __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400)
#define __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40600)
#define __RANDOM_ITERATOR_TBB_CPP11_STD_BEGIN_END_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40600)
#define __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400)
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40400)
#define __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40500)
#define __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40300)
#define __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40700)
#define __RANDOM_ITERATOR_TBB_ALIGNAS_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40800)
#define __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40700)
#define __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT (__cplusplus >= 201402L && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 50000)
#define __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__cplusplus >= 201402L && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 50000)
#define __RANDOM_ITERATOR_TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cpp_deduction_guides >= 201606L)
#define __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT (__cplusplus >= 201703L && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 70000)
#elif _MSC_VER
// These definitions are also used with Intel C++ Compiler in "default" mode (__INTEL_CXX11_MODE__ == 0);
// see a comment in "__INTEL_COMPILER" section above.
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT (_MSC_VER >= 1800)
// Contains a workaround for ICC 13
#define __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT (_MSC_VER >= 1700 && (!__INTEL_COMPILER || __INTEL_COMPILER >= 1400))
#define __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT (_MSC_VER >= 1900)
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_CPP11_TUPLE_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT (_MSC_VER >= 1800)
#define __RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT (_MSC_VER >= 1900)
#define __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT (_MSC_VER >= 1800)
#define __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT (_MSC_VER >= 1900)
#define __RANDOM_ITERATOR_TBB_CPP11_STD_BEGIN_END_PRESENT (_MSC_VER >= 1700)
#define __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT (_MSC_VER >= 1600)
#define __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT (_MSC_VER >= 1800)
#define __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT (_MSC_VER >= 1700)
#define __RANDOM_ITERATOR_TBB_ALIGNAS_PRESENT (_MSC_VER >= 1900)
#define __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT (_MSC_VER >= 1800)
#define __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT (_MSC_VER >= 1900)
/* Variable templates are supported in VS2015 Update 2 or later */
#define __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (_MSC_FULL_VER >= 190023918 && (!__INTEL_COMPILER || __INTEL_COMPILER >= 1700))
#define __RANDOM_ITERATOR_TBB_CPP17_DEDUCTION_GUIDES_PRESENT (_MSVC_LANG >= 201703L && _MSC_VER >= 1914)
#define __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT (_MSVC_LANG >= 201703L && _MSC_VER >= 1911)
#else
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_TUPLE_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_STD_BEGIN_END_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_ALIGNAS_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT __RANDOM_ITERATOR_TBB_CPP11_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP14_INTEGER_SEQUENCE_PRESENT (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_CPP14_VARIABLE_TEMPLATES_PRESENT (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_CPP17_DEDUCTION_GUIDES_PRESENT (__cplusplus >= 201703L)
#define __RANDOM_ITERATOR_TBB_CPP17_INVOKE_RESULT_PRESENT (__cplusplus >= 201703L)
#endif
// C++11 standard library features
#define __RANDOM_ITERATOR_TBB_CPP11_ARRAY_PRESENT (_MSC_VER >= 1700 || _LIBCPP_VERSION || __GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40300)
#ifndef __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_FIXED_LENGTH_EXP_PRESENT
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_FIXED_LENGTH_EXP_PRESENT __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
#endif
#define __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TUPLE_PRESENT (!_MSC_VER || _MSC_VER >= 1800)
#define __RANDOM_ITERATOR_TBB_CPP11_TYPE_PROPERTIES_PRESENT (_LIBCPP_VERSION || _MSC_VER >= 1700 || (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 50000 && __GXX_EXPERIMENTAL_CXX0X__))
// GCC supported some of type properties since 4.7
#define __RANDOM_ITERATOR_TBB_CPP11_IS_COPY_CONSTRUCTIBLE_PRESENT (__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40700 || __RANDOM_ITERATOR_TBB_CPP11_TYPE_PROPERTIES_PRESENT)
// In GCC, std::move_if_noexcept appeared later than noexcept
#define __RANDOM_ITERATOR_TBB_MOVE_IF_NOEXCEPT_PRESENT (__RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40700 || _MSC_VER >= 1900 || _LIBCPP_VERSION))
#define __RANDOM_ITERATOR_TBB_ALLOCATOR_TRAITS_PRESENT (__cplusplus >= 201103L && _LIBCPP_VERSION || _MSC_VER >= 1800 || \
__GXX_EXPERIMENTAL_CXX0X__ && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40700 && !(__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION == 40700 && __RANDOM_ITERATOR_TBB_DEFINE_MIC))
#define __RANDOM_ITERATOR_TBB_MAKE_EXCEPTION_PTR_PRESENT (__RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT && (_MSC_VER >= 1700 || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600 || _LIBCPP_VERSION || __SUNPRO_CC))
// Due to libc++ limitations in C++03 mode, do not pass rvalues to std::make_shared()
#define __RANDOM_ITERATOR_TBB_CPP11_SMART_POINTERS_PRESENT ( _MSC_VER >= 1600 || _LIBCPP_VERSION \
|| ((__cplusplus >= 201103L || __GXX_EXPERIMENTAL_CXX0X__) \
&& (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40500 || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40400 && __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_OPTIONAL_RTTI)) )
#define __RANDOM_ITERATOR_TBB_CPP11_FUTURE_PRESENT (_MSC_VER >= 1700 || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40600 && __GXX_EXPERIMENTAL_CXX0X__ || _LIBCPP_VERSION)
#define __RANDOM_ITERATOR_TBB_CPP11_GET_NEW_HANDLER_PRESENT (_MSC_VER >= 1900 || __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION >= 40900 && __GXX_EXPERIMENTAL_CXX0X__ || _LIBCPP_VERSION)
#define __RANDOM_ITERATOR_TBB_CPP17_UNCAUGHT_EXCEPTIONS_PRESENT (_MSC_VER >= 1900 || __GLIBCXX__ && __cpp_lib_uncaught_exceptions \
|| _LIBCPP_VERSION >= 3700 && (!__RANDOM_ITERATOR_TBB_MACOS_TARGET_VERSION || __RANDOM_ITERATOR_TBB_MACOS_TARGET_VERSION >= 101200))
// TODO: wait when memory_resource will be fully supported in clang and define the right macro
// Currently it is in experimental stage since 6 version.
#define __RANDOM_ITERATOR_TBB_CPP17_MEMORY_RESOURCE_PRESENT (_MSC_VER >= 1913 && (_MSVC_LANG > 201402L || __cplusplus > 201402L) || \
__GLIBCXX__ && __cpp_lib_memory_resource >= 201603)
#define __RANDOM_ITERATOR_TBB_CPP17_HW_INTERFERENCE_SIZE_PRESENT (_MSC_VER >= 1911)
// std::swap is in <utility> only since C++11, though MSVC had it at least since VS2005
#if _MSC_VER>=1400 || _LIBCPP_VERSION || __GXX_EXPERIMENTAL_CXX0X__
#define __RANDOM_ITERATOR_TBB_STD_SWAP_HEADER <utility>
#else
#define __RANDOM_ITERATOR_TBB_STD_SWAP_HEADER <algorithm>
#endif
//TODO: not clear how exactly this macro affects exception_ptr - investigate
// On linux ICC fails to find existing std::exception_ptr in libstdc++ without this define
#if __INTEL_COMPILER && __GNUC__ && __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#endif
// Work around a bug in MinGW32
#if __MINGW32__ && __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT && !defined(_GLIBCXX_ATOMIC_BUILTINS_4)
#define _GLIBCXX_ATOMIC_BUILTINS_4
#endif
#if __GNUC__ || __SUNPRO_CC || __IBMCPP__
/* ICC defines __GNUC__ and so is covered */
#define __RANDOM_ITERATOR_TBB_ATTRIBUTE_ALIGNED_PRESENT 1
#elif _MSC_VER && (_MSC_VER >= 1300 || __INTEL_COMPILER)
#define __RANDOM_ITERATOR_TBB_DECLSPEC_ALIGN_PRESENT 1
#endif
/* Actually ICC supports gcc __sync_* intrinsics starting 11.1,
* but 64 bit support for 32 bit target comes in later ones*/
/* TODO: change the version back to 4.1.2 once macro __RANDOM_ITERATOR_TBB_WORD_SIZE become optional */
/* Assumed that all clang versions have these gcc compatible intrinsics. */
#if __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40306 || __INTEL_COMPILER >= 1200 || __clang__
/** built-in atomics available in GCC since 4.1.2 **/
#define __RANDOM_ITERATOR_TBB_GCC_BUILTIN_ATOMICS_PRESENT 1
#endif
#if __RANDOM_ITERATOR_TBB_GCC_VERSION >= 70000 && !__INTEL_COMPILER && !__clang__
// After GCC7 there was possible reordering problem in generic atomic load/store operations.
// So always using builtins.
#define RANDOM_ITERATOR_TBB_USE_GCC_BUILTINS 1
#endif
#if __INTEL_COMPILER >= 1200
/** built-in C++11 style atomics available in ICC since 12.0 **/
#define __RANDOM_ITERATOR_TBB_ICC_BUILTIN_ATOMICS_PRESENT 1
#endif
#if _MSC_VER>=1600 && (!__INTEL_COMPILER || __INTEL_COMPILER>=1310)
#define __RANDOM_ITERATOR_TBB_MSVC_PART_WORD_INTERLOCKED_INTRINSICS_PRESENT 1
#endif
#define __RANDOM_ITERATOR_TBB_TSX_INTRINSICS_PRESENT ((__RTM__ || _MSC_VER>=1700 || __INTEL_COMPILER>=1300) && !__RANDOM_ITERATOR_TBB_DEFINE_MIC && !__ANDROID__)
/** Macro helpers **/
#define __RANDOM_ITERATOR_TBB_CONCAT_AUX(A,B) A##B
// The additional level of indirection is needed to expand macros A and B (not to get the AB macro).
// See [cpp.subst] and [cpp.concat] for more details.
#define __RANDOM_ITERATOR_TBB_CONCAT(A,B) __RANDOM_ITERATOR_TBB_CONCAT_AUX(A,B)
// The IGNORED argument and comma are needed to always have 2 arguments (even when A is empty).
#define __RANDOM_ITERATOR_TBB_IS_MACRO_EMPTY(A,IGNORED) __RANDOM_ITERATOR_TBB_CONCAT_AUX(__RANDOM_ITERATOR_TBB_MACRO_EMPTY,A)
#define __RANDOM_ITERATOR_TBB_MACRO_EMPTY 1
/** User controlled TBB features & modes **/
#ifndef RANDOM_ITERATOR_TBB_USE_DEBUG
/*
There are four cases that are supported:
1. "_DEBUG is undefined" means "no debug";
2. "_DEBUG defined to something that is evaluated to 0" (including "garbage", as per [cpp.cond]) means "no debug";
3. "_DEBUG defined to something that is evaluated to a non-zero value" means "debug";
4. "_DEBUG defined to nothing (empty)" means "debug".
*/
#ifdef _DEBUG
// Check if _DEBUG is empty.
#define __RANDOM_ITERATOR_TBB_IS__DEBUG_EMPTY (__RANDOM_ITERATOR_TBB_IS_MACRO_EMPTY(_DEBUG,IGNORED)==__RANDOM_ITERATOR_TBB_MACRO_EMPTY)
#if __RANDOM_ITERATOR_TBB_IS__DEBUG_EMPTY
#define RANDOM_ITERATOR_TBB_USE_DEBUG 1
#else
#define RANDOM_ITERATOR_TBB_USE_DEBUG _DEBUG
#endif /* __RANDOM_ITERATOR_TBB_IS__DEBUG_EMPTY */
#else
#define RANDOM_ITERATOR_TBB_USE_DEBUG 0
#endif
#endif /* RANDOM_ITERATOR_TBB_USE_DEBUG */
#ifndef RANDOM_ITERATOR_TBB_USE_ASSERT
#define RANDOM_ITERATOR_TBB_USE_ASSERT RANDOM_ITERATOR_TBB_USE_DEBUG
#endif /* RANDOM_ITERATOR_TBB_USE_ASSERT */
#ifndef RANDOM_ITERATOR_TBB_USE_THREADING_TOOLS
#define RANDOM_ITERATOR_TBB_USE_THREADING_TOOLS RANDOM_ITERATOR_TBB_USE_DEBUG
#endif /* RANDOM_ITERATOR_TBB_USE_THREADING_TOOLS */
#ifndef RANDOM_ITERATOR_TBB_USE_PERFORMANCE_WARNINGS
#ifdef RANDOM_ITERATOR_TBB_PERFORMANCE_WARNINGS
#define RANDOM_ITERATOR_TBB_USE_PERFORMANCE_WARNINGS RANDOM_ITERATOR_TBB_PERFORMANCE_WARNINGS
#else
#define RANDOM_ITERATOR_TBB_USE_PERFORMANCE_WARNINGS RANDOM_ITERATOR_TBB_USE_DEBUG
#endif /* RANDOM_ITERATOR_TBB_PERFORMANCE_WARNINGS */
#endif /* RANDOM_ITERATOR_TBB_USE_PERFORMANCE_WARNINGS */
#if __RANDOM_ITERATOR_TBB_DEFINE_MIC
#if RANDOM_ITERATOR_TBB_USE_EXCEPTIONS
#error The platform does not properly support exception handling. Please do not set RANDOM_ITERATOR_TBB_USE_EXCEPTIONS macro or set it to 0.
#elif !defined(RANDOM_ITERATOR_TBB_USE_EXCEPTIONS)
#define RANDOM_ITERATOR_TBB_USE_EXCEPTIONS 0
#endif
#elif !(__EXCEPTIONS || defined(_CPPUNWIND) || __SUNPRO_CC)
#if RANDOM_ITERATOR_TBB_USE_EXCEPTIONS
#error Compilation settings do not support exception handling. Please do not set RANDOM_ITERATOR_TBB_USE_EXCEPTIONS macro or set it to 0.
#elif !defined(RANDOM_ITERATOR_TBB_USE_EXCEPTIONS)
#define RANDOM_ITERATOR_TBB_USE_EXCEPTIONS 0
#endif
#elif !defined(RANDOM_ITERATOR_TBB_USE_EXCEPTIONS)
#define RANDOM_ITERATOR_TBB_USE_EXCEPTIONS 1
#endif
#ifndef RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X
/** By default, use C++11 classes if available **/
#if __clang__
/* Old versions of Intel C++ Compiler do not have __has_include or cannot use it in #define */
#if (__INTEL_COMPILER && (__INTEL_COMPILER < 1500 || __INTEL_COMPILER == 1500 && __INTEL_COMPILER_UPDATE <= 1))
#define RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X (__cplusplus < 201103L || !_LIBCPP_VERSION)
#else
#define RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X (__cplusplus < 201103L || (!__has_include(<thread>) && !__has_include(<condition_variable>)))
#endif
#elif __GNUC__
#define RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X (__RANDOM_ITERATOR_TBB_GCC_VERSION < 40400 || !__GXX_EXPERIMENTAL_CXX0X__)
#elif _MSC_VER
#define RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X (_MSC_VER < 1700)
#else
// TODO: Reconsider general approach to be more reliable, e.g. (!(__cplusplus >= 201103L && __ STDC_HOSTED__))
#define RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X (!__STDCPP_THREADS__)
#endif
#endif /* RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X */
/* RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION should be explicitly set to either 0 or 1, as it is used as C++ const */
#ifndef RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION
/** IA-64 architecture pre-built TBB binaries do not support exception_ptr. **/
#if __RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT && !defined(__ia64__)
#define RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION 0
#else
#define RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION 1
#endif
#else /* defined RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION */
#if !RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION && !__RANDOM_ITERATOR_TBB_EXCEPTION_PTR_PRESENT
#error Current runtime does not support std::exception_ptr. Set RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION and make sure that your code is ready to catch tbb::captured_exception.
#endif
#endif /* defined RANDOM_ITERATOR_TBB_USE_CAPTURED_EXCEPTION */
/** Check whether the request to use GCC atomics can be satisfied **/
#if RANDOM_ITERATOR_TBB_USE_GCC_BUILTINS && !__RANDOM_ITERATOR_TBB_GCC_BUILTIN_ATOMICS_PRESENT
#error "GCC atomic built-ins are not supported."
#endif
/** Internal TBB features & modes **/
/** __RANDOM_ITERATOR_TBB_CONCURRENT_ORDERED_CONTAINERS indicates that all conditions of use
* concurrent_map and concurrent_set are met. **/
// TODO: Add cpp11 random generation macro
#ifndef __RANDOM_ITERATOR_TBB_CONCURRENT_ORDERED_CONTAINERS_PRESENT
#define __RANDOM_ITERATOR_TBB_CONCURRENT_ORDERED_CONTAINERS_PRESENT ( __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT \
&& __RANDOM_ITERATOR_TBB_IMPLICIT_MOVE_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_LAMBDAS_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_ARRAY_PRESENT \
&& __RANDOM_ITERATOR_TBB_INITIALIZER_LISTS_PRESENT )
#endif
/** __RANDOM_ITERATOR_TBB_WEAK_SYMBOLS_PRESENT denotes that the system supports the weak symbol mechanism **/
#ifndef __RANDOM_ITERATOR_TBB_WEAK_SYMBOLS_PRESENT
#define __RANDOM_ITERATOR_TBB_WEAK_SYMBOLS_PRESENT ( !_WIN32 && !__APPLE__ && !__sun && (__RANDOM_ITERATOR_TBB_GCC_VERSION >= 40000 || __INTEL_COMPILER ) )
#endif
/** __RANDOM_ITERATOR_TBB_DYNAMIC_LOAD_ENABLED describes the system possibility to load shared libraries at run time **/
#ifndef __RANDOM_ITERATOR_TBB_DYNAMIC_LOAD_ENABLED
#define __RANDOM_ITERATOR_TBB_DYNAMIC_LOAD_ENABLED 1
#endif
/** __RANDOM_ITERATOR_TBB_SOURCE_DIRECTLY_INCLUDED is a mode used in whitebox testing when
it's necessary to test internal functions not exported from TBB DLLs
**/
#if (_WIN32||_WIN64) && (__RANDOM_ITERATOR_TBB_SOURCE_DIRECTLY_INCLUDED || RANDOM_ITERATOR_TBB_USE_PREVIEW_BINARY)
#define __RANDOM_ITERATOR_TBB_NO_IMPLICIT_LINKAGE 1
#define __RANDOM_ITERATOR_TBBMALLOC_NO_IMPLICIT_LINKAGE 1
#endif
#ifndef __RANDOM_ITERATOR_TBB_COUNT_TASK_NODES
#define __RANDOM_ITERATOR_TBB_COUNT_TASK_NODES RANDOM_ITERATOR_TBB_USE_ASSERT
#endif
#ifndef __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT
#define __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT 1
#endif /* __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT */
#ifndef __RANDOM_ITERATOR_TBB_SCHEDULER_OBSERVER
#define __RANDOM_ITERATOR_TBB_SCHEDULER_OBSERVER 1
#endif /* __RANDOM_ITERATOR_TBB_SCHEDULER_OBSERVER */
#ifndef __RANDOM_ITERATOR_TBB_FP_CONTEXT
#define __RANDOM_ITERATOR_TBB_FP_CONTEXT __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT
#endif /* __RANDOM_ITERATOR_TBB_FP_CONTEXT */
#if __RANDOM_ITERATOR_TBB_FP_CONTEXT && !__RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT
#error __RANDOM_ITERATOR_TBB_FP_CONTEXT requires __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT to be enabled
#endif
#define __RANDOM_ITERATOR_TBB_RECYCLE_TO_ENQUEUE __RANDOM_ITERATOR_TBB_BUILD // keep non-official
#ifndef __RANDOM_ITERATOR_TBB_ARENA_OBSERVER
#define __RANDOM_ITERATOR_TBB_ARENA_OBSERVER __RANDOM_ITERATOR_TBB_SCHEDULER_OBSERVER
#endif /* __RANDOM_ITERATOR_TBB_ARENA_OBSERVER */
#ifndef __RANDOM_ITERATOR_TBB_TASK_ISOLATION
#define __RANDOM_ITERATOR_TBB_TASK_ISOLATION 1
#endif /* __RANDOM_ITERATOR_TBB_TASK_ISOLATION */
#if RANDOM_ITERATOR_TBB_USE_EXCEPTIONS && !__RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT
#error RANDOM_ITERATOR_TBB_USE_EXCEPTIONS requires __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT to be enabled
#endif
#ifndef __RANDOM_ITERATOR_TBB_TASK_PRIORITY
#define __RANDOM_ITERATOR_TBB_TASK_PRIORITY (__RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT)
#endif /* __RANDOM_ITERATOR_TBB_TASK_PRIORITY */
#if __RANDOM_ITERATOR_TBB_TASK_PRIORITY && !__RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT
#error __RANDOM_ITERATOR_TBB_TASK_PRIORITY requires __RANDOM_ITERATOR_TBB_TASK_GROUP_CONTEXT to be enabled
#endif
#if RANDOM_ITERATOR_TBB_PREVIEW_NUMA_SUPPORT || __RANDOM_ITERATOR_TBB_BUILD
#define __RANDOM_ITERATOR_TBB_NUMA_SUPPORT 1
#endif
#if RANDOM_ITERATOR_TBB_PREVIEW_WAITING_FOR_WORKERS || __RANDOM_ITERATOR_TBB_BUILD
#define __RANDOM_ITERATOR_TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE 1
#endif
#ifndef __RANDOM_ITERATOR_TBB_ENQUEUE_ENFORCED_CONCURRENCY
#define __RANDOM_ITERATOR_TBB_ENQUEUE_ENFORCED_CONCURRENCY 1
#endif
#if !defined(__RANDOM_ITERATOR_TBB_SURVIVE_THREAD_SWITCH) && \
(_WIN32 || _WIN64 || __APPLE__ || (__linux__ && !__ANDROID__))
#define __RANDOM_ITERATOR_TBB_SURVIVE_THREAD_SWITCH 1
#endif /* __RANDOM_ITERATOR_TBB_SURVIVE_THREAD_SWITCH */
#ifndef __RANDOM_ITERATOR_TBB_DEFAULT_PARTITIONER
#define __RANDOM_ITERATOR_TBB_DEFAULT_PARTITIONER tbb::auto_partitioner
#endif
#ifndef __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_PROPORTIONAL_SPLIT_IN_BLOCKED_RANGES 1
#endif
#ifndef __RANDOM_ITERATOR_TBB_ENABLE_RANGE_FEEDBACK
#define __RANDOM_ITERATOR_TBB_ENABLE_RANGE_FEEDBACK 0
#endif
#ifdef _VARIADIC_MAX
#define __RANDOM_ITERATOR_TBB_VARIADIC_MAX _VARIADIC_MAX
#else
#if _MSC_VER == 1700
#define __RANDOM_ITERATOR_TBB_VARIADIC_MAX 5 // VS11 setting, issue resolved in VS12
#elif _MSC_VER == 1600
#define __RANDOM_ITERATOR_TBB_VARIADIC_MAX 10 // VS10 setting
#else
#define __RANDOM_ITERATOR_TBB_VARIADIC_MAX 15
#endif
#endif
// Intel C++ Compiler starts analyzing usages of the deprecated content at the template
// instantiation site, which is too late for suppression of the corresponding messages for internal
// stuff.
#if !defined(__INTEL_COMPILER) && (!defined(TBB_SUPPRESS_DEPRECATED_MESSAGES) || (TBB_SUPPRESS_DEPRECATED_MESSAGES == 0))
#if (__cplusplus >= 201402L)
#define __RANDOM_ITERATOR_TBB_DEPRECATED [[deprecated]]
#define __RANDOM_ITERATOR_TBB_DEPRECATED_MSG(msg) [[deprecated(msg)]]
#elif _MSC_VER
#define __RANDOM_ITERATOR_TBB_DEPRECATED __declspec(deprecated)
#define __RANDOM_ITERATOR_TBB_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
#elif (__GNUC__ && __RANDOM_ITERATOR_TBB_GCC_VERSION >= 40805) || __clang__
#define __RANDOM_ITERATOR_TBB_DEPRECATED __attribute__((deprecated))
#define __RANDOM_ITERATOR_TBB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
#endif
#endif // !defined(TBB_SUPPRESS_DEPRECATED_MESSAGES) || (TBB_SUPPRESS_DEPRECATED_MESSAGES == 0)
#if !defined(__RANDOM_ITERATOR_TBB_DEPRECATED)
#define __RANDOM_ITERATOR_TBB_DEPRECATED
#define __RANDOM_ITERATOR_TBB_DEPRECATED_MSG(msg)
#elif !defined(__RANDOM_ITERATOR_TBB_SUPPRESS_INTERNAL_DEPRECATED_MESSAGES)
// Suppress deprecated messages from self
#define __RANDOM_ITERATOR_TBB_SUPPRESS_INTERNAL_DEPRECATED_MESSAGES 1
#endif
#if defined(TBB_SUPPRESS_DEPRECATED_MESSAGES) && (TBB_SUPPRESS_DEPRECATED_MESSAGES == 0)
#define __RANDOM_ITERATOR_TBB_DEPRECATED_IN_VERBOSE_MODE __RANDOM_ITERATOR_TBB_DEPRECATED
#define __RANDOM_ITERATOR_TBB_DEPRECATED_IN_VERBOSE_MODE_MSG(msg) __RANDOM_ITERATOR_TBB_DEPRECATED_MSG(msg)
#else
#define __RANDOM_ITERATOR_TBB_DEPRECATED_IN_VERBOSE_MODE
#define __RANDOM_ITERATOR_TBB_DEPRECATED_IN_VERBOSE_MODE_MSG(msg)
#endif // (TBB_SUPPRESS_DEPRECATED_MESSAGES == 0)
#if (!defined(TBB_SUPPRESS_DEPRECATED_MESSAGES) || (TBB_SUPPRESS_DEPRECATED_MESSAGES == 0)) && !__RANDOM_ITERATOR_TBB_CPP11_PRESENT
#pragma message("TBB Warning: Support for C++98/03 is deprecated. Please use the compiler that supports C++11 features at least.")
#endif
/** __RANDOM_ITERATOR_TBB_WIN8UI_SUPPORT enables support of Windows* Store Apps and limit a possibility to load
shared libraries at run time only from application container **/
// TODO: Separate this single macro into two for Windows 8 Store* (win8ui mode) and UWP/UWD modes.
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP
#define __RANDOM_ITERATOR_TBB_WIN8UI_SUPPORT 1
#else
#define __RANDOM_ITERATOR_TBB_WIN8UI_SUPPORT 0
#endif
/** Macros of the form __RANDOM_ITERATOR_TBB_XXX_BROKEN denote known issues that are caused by
the bugs in compilers, standard or OS specific libraries. They should be
removed as soon as the corresponding bugs are fixed or the buggy OS/compiler
versions go out of the support list.
**/
#if __SIZEOF_POINTER__ < 8 && __ANDROID__ && __RANDOM_ITERATOR_TBB_GCC_VERSION <= 40403 && !__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
/** Necessary because on Android 8-byte CAS and F&A are not available for some processor architectures,
but no mandatory warning message appears from GCC 4.4.3. Instead, only a linkage error occurs when
these atomic operations are used (such as in unit test test_atomic.exe). **/
#define __RANDOM_ITERATOR_TBB_GCC_64BIT_ATOMIC_BUILTINS_BROKEN 1
#elif __RANDOM_ITERATOR_TBB_x86_32 && __RANDOM_ITERATOR_TBB_GCC_VERSION == 40102 && ! __GNUC_RH_RELEASE__
/** GCC 4.1.2 erroneously emit call to external function for 64 bit sync_ intrinsics.
However these functions are not defined anywhere. It seems that this problem was fixed later on
and RHEL got an updated version of gcc 4.1.2. **/
#define __RANDOM_ITERATOR_TBB_GCC_64BIT_ATOMIC_BUILTINS_BROKEN 1
#endif
#if __GNUC__ && __RANDOM_ITERATOR_TBB_x86_64 && __INTEL_COMPILER == 1200
#define __RANDOM_ITERATOR_TBB_ICC_12_0_INL_ASM_FSTCW_BROKEN 1
#endif
#if _MSC_VER && __INTEL_COMPILER && (__INTEL_COMPILER<1110 || __INTEL_COMPILER==1110 && __INTEL_COMPILER_BUILD_DATE < 20091012)
/** Necessary to avoid ICL error (or warning in non-strict mode):
"exception specification for implicitly declared virtual destructor is
incompatible with that of overridden one". **/
#define __RANDOM_ITERATOR_TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN 1
#endif
#if !__INTEL_COMPILER && (_MSC_VER && _MSC_VER < 1500 || __GNUC__ && __RANDOM_ITERATOR_TBB_GCC_VERSION < 40102)
/** gcc 3.4.6 (and earlier) and VS2005 (and earlier) do not allow declaring template class as a friend
of classes defined in other namespaces. **/
#define __RANDOM_ITERATOR_TBB_TEMPLATE_FRIENDS_BROKEN 1
#endif
#if __GLIBC__==2 && __GLIBC_MINOR__==3 || (__APPLE__ && ( __INTEL_COMPILER==1200 && !RANDOM_ITERATOR_TBB_USE_DEBUG))
/** Macro controlling EH usages in TBB tests.
Some older versions of glibc crash when exception handling happens concurrently. **/
#define __RANDOM_ITERATOR_TBB_THROW_ACROSS_MODULE_BOUNDARY_BROKEN 1
#endif
#if (_WIN32||_WIN64) && __INTEL_COMPILER == 1110
/** That's a bug in Intel C++ Compiler 11.1.044/IA-32 architecture/Windows* OS, that leads to a worker thread crash on the thread's startup. **/
#define __RANDOM_ITERATOR_TBB_ICL_11_1_CODE_GEN_BROKEN 1
#endif
#if __clang__ || (__GNUC__==3 && __GNUC_MINOR__==3 && !defined(__INTEL_COMPILER))
/** Bugs with access to nested classes declared in protected area */
#define __RANDOM_ITERATOR_TBB_PROTECTED_NESTED_CLASS_BROKEN 1
#endif
#if __MINGW32__ && __RANDOM_ITERATOR_TBB_GCC_VERSION < 40200
/** MinGW has a bug with stack alignment for routines invoked from MS RTLs.
Since GCC 4.2, the bug can be worked around via a special attribute. **/
#define __RANDOM_ITERATOR_TBB_SSE_STACK_ALIGNMENT_BROKEN 1
#endif
#if __RANDOM_ITERATOR_TBB_GCC_VERSION==40300 && !__INTEL_COMPILER && !__clang__
/* GCC of this version may rashly ignore control dependencies */
#define __RANDOM_ITERATOR_TBB_GCC_OPTIMIZER_ORDERING_BROKEN 1
#endif
#if __FreeBSD__
/** A bug in FreeBSD 8.0 results in kernel panic when there is contention
on a mutex created with this attribute. **/
#define __RANDOM_ITERATOR_TBB_PRIO_INHERIT_BROKEN 1
/** A bug in FreeBSD 8.0 results in test hanging when an exception occurs
during (concurrent?) object construction by means of placement new operator. **/
#define __RANDOM_ITERATOR_TBB_PLACEMENT_NEW_EXCEPTION_SAFETY_BROKEN 1
#endif /* __FreeBSD__ */
#if (__linux__ || __APPLE__) && __i386__ && defined(__INTEL_COMPILER)
/** The Intel C++ Compiler for IA-32 architecture (Linux* OS|macOS) crashes or generates
incorrect code when __asm__ arguments have a cast to volatile. **/
#define __RANDOM_ITERATOR_TBB_ICC_ASM_VOLATILE_BROKEN 1
#endif
#if !__INTEL_COMPILER && (_MSC_VER && _MSC_VER < 1700 || __GNUC__==3 && __GNUC_MINOR__<=2)
/** Bug in GCC 3.2 and MSVC compilers that sometimes return 0 for __alignof(T)
when T has not yet been instantiated. **/
#define __RANDOM_ITERATOR_TBB_ALIGNOF_NOT_INSTANTIATED_TYPES_BROKEN 1
#endif
#if __RANDOM_ITERATOR_TBB_DEFINE_MIC
/** Main thread and user's thread have different default thread affinity masks. **/
#define __RANDOM_ITERATOR_TBB_MAIN_THREAD_AFFINITY_BROKEN 1
#endif
#if __GXX_EXPERIMENTAL_CXX0X__ && !defined(__EXCEPTIONS) && \
((!__INTEL_COMPILER && !__clang__ && (__RANDOM_ITERATOR_TBB_GCC_VERSION>=40400 && __RANDOM_ITERATOR_TBB_GCC_VERSION<40600)) || \
(__INTEL_COMPILER<=1400 && (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION>=40400 && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION<=40801)))
/* There is an issue for specific GCC toolchain when C++11 is enabled
and exceptions are disabled:
exceprion_ptr.h/nested_exception.h use throw unconditionally.
GCC can ignore 'throw' since 4.6; but with ICC the issue still exists.
*/
#define __RANDOM_ITERATOR_TBB_LIBSTDCPP_EXCEPTION_HEADERS_BROKEN 1
#endif
#if __INTEL_COMPILER==1300 && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION>=40700 && defined(__GXX_EXPERIMENTAL_CXX0X__)
/* Some C++11 features used inside libstdc++ are not supported by Intel C++ Compiler. */
#define __RANDOM_ITERATOR_TBB_ICC_13_0_CPP11_STDLIB_SUPPORT_BROKEN 1
#endif
#if (__GNUC__==4 && __GNUC_MINOR__==4 ) && !defined(__INTEL_COMPILER) && !defined(__clang__)
/** excessive warnings related to strict aliasing rules in GCC 4.4 **/
#define __RANDOM_ITERATOR_TBB_GCC_STRICT_ALIASING_BROKEN 1
/* topical remedy: #pragma GCC diagnostic ignored "-Wstrict-aliasing" */
#if !__RANDOM_ITERATOR_TBB_GCC_WARNING_SUPPRESSION_PRESENT
#error Warning suppression is not supported, while should.
#endif
#endif
/* In a PIC mode some versions of GCC 4.1.2 generate incorrect inlined code for 8 byte __sync_val_compare_and_swap intrinsic */
#if __RANDOM_ITERATOR_TBB_GCC_VERSION == 40102 && __PIC__ && !defined(__INTEL_COMPILER) && !defined(__clang__)
#define __RANDOM_ITERATOR_TBB_GCC_CAS8_BUILTIN_INLINING_BROKEN 1
#endif
#if __RANDOM_ITERATOR_TBB_x86_32 && ( __INTEL_COMPILER || (__GNUC__==5 && __GNUC_MINOR__>=2 && __GXX_EXPERIMENTAL_CXX0X__) \
|| (__GNUC__==3 && __GNUC_MINOR__==3) || (__MINGW32__ && __GNUC__==4 && __GNUC_MINOR__==5) || __SUNPRO_CC )
// Some compilers for IA-32 architecture fail to provide 8-byte alignment of objects on the stack,
// even if the object specifies 8-byte alignment. On such platforms, the implementation
// of 64 bit atomics for IA-32 architecture (e.g. atomic<long long>) use different tactics
// depending upon whether the object is properly aligned or not.
#define __RANDOM_ITERATOR_TBB_FORCE_64BIT_ALIGNMENT_BROKEN 1
#else
// Define to 0 explicitly because the macro is used in a compiled code of test_atomic
#define __RANDOM_ITERATOR_TBB_FORCE_64BIT_ALIGNMENT_BROKEN 0
#endif
#if __GNUC__ && !__INTEL_COMPILER && !__clang__ && __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT && __RANDOM_ITERATOR_TBB_GCC_VERSION < 40700
#define __RANDOM_ITERATOR_TBB_ZERO_INIT_WITH_DEFAULTED_CTOR_BROKEN 1
#endif
#if _MSC_VER && _MSC_VER <= 1800 && !__INTEL_COMPILER
// With MSVC, when an array is passed by const reference to a template function,
// constness from the function parameter may get propagated to the template parameter.
#define __RANDOM_ITERATOR_TBB_CONST_REF_TO_ARRAY_TEMPLATE_PARAM_BROKEN 1
#endif
// A compiler bug: a disabled copy constructor prevents use of the moving constructor
#define __RANDOM_ITERATOR_TBB_IF_NO_COPY_CTOR_MOVE_SEMANTICS_BROKEN (_MSC_VER && (__INTEL_COMPILER >= 1300 && __INTEL_COMPILER <= 1310) && !__INTEL_CXX11_MODE__)
#define __RANDOM_ITERATOR_TBB_CPP11_DECLVAL_BROKEN (_MSC_VER == 1600 || (__GNUC__ && __RANDOM_ITERATOR_TBB_GCC_VERSION < 40500) )
// Intel C++ Compiler has difficulties with copying std::pair with VC11 std::reference_wrapper being a const member
#define __RANDOM_ITERATOR_TBB_COPY_FROM_NON_CONST_REF_BROKEN (_MSC_VER == 1700 && __INTEL_COMPILER && __INTEL_COMPILER < 1600)
// The implicit upcasting of the tuple of a reference of a derived class to a base class fails on icc 13.X if the system's gcc environment is 4.8
// Also in gcc 4.4 standard library the implementation of the tuple<&> conversion (tuple<A&> a = tuple<B&>, B is inherited from A) is broken.
#if __GXX_EXPERIMENTAL_CXX0X__ && __GLIBCXX__ && ((__INTEL_COMPILER >=1300 && __INTEL_COMPILER <=1310 && __RANDOM_ITERATOR_TBB_GLIBCXX_VERSION>=40700) || (__RANDOM_ITERATOR_TBB_GLIBCXX_VERSION < 40500))
#define __RANDOM_ITERATOR_TBB_UPCAST_OF_TUPLE_OF_REF_BROKEN 1
#endif
// In some cases decltype of a function adds a reference to a return type.
#define __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_OF_FUNCTION_RETURN_TYPE_BROKEN (_MSC_VER == 1600 && !__INTEL_COMPILER)
// Visual Studio 2013 does not delete the copy constructor when a user-defined move constructor is provided
#if _MSC_VER && _MSC_VER <= 1800
#define __RANDOM_ITERATOR_TBB_IMPLICIT_COPY_DELETION_BROKEN 1
#endif
/** End of __RANDOM_ITERATOR_TBB_XXX_BROKEN macro section **/
#if defined(_MSC_VER) && _MSC_VER>=1500 && !defined(__INTEL_COMPILER)
// A macro to suppress erroneous or benign "unreachable code" MSVC warning (4702)
#define __RANDOM_ITERATOR_TBB_MSVC_UNREACHABLE_CODE_IGNORED 1
#endif
#define __RANDOM_ITERATOR_TBB_ATOMIC_CTORS (__RANDOM_ITERATOR_TBB_CONSTEXPR_PRESENT && __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT && (!__RANDOM_ITERATOR_TBB_ZERO_INIT_WITH_DEFAULTED_CTOR_BROKEN))
// Many OS versions (Android 4.0.[0-3] for example) need workaround for dlopen to avoid non-recursive loader lock hang
// Setting the workaround for all compile targets ($APP_PLATFORM) below Android 4.4 (android-19)
#if __ANDROID__
#include <android/api-level.h>
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_USE_DLOPEN_REENTRANCY_WORKAROUND (__ANDROID_API__ < 19)
#endif
#define __RANDOM_ITERATOR_TBB_ALLOCATOR_CONSTRUCT_VARIADIC (__RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT)
#define __RANDOM_ITERATOR_TBB_VARIADIC_PARALLEL_INVOKE (RANDOM_ITERATOR_TBB_PREVIEW_VARIADIC_PARALLEL_INVOKE && __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT)
#define __RANDOM_ITERATOR_TBB_FLOW_GRAPH_CPP11_FEATURES (__RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT \
&& __RANDOM_ITERATOR_TBB_CPP11_SMART_POINTERS_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_AUTO_PRESENT) \
&& __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TUPLE_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_DEFAULT_FUNC_TEMPLATE_ARGS_PRESENT \
&& !__RANDOM_ITERATOR_TBB_UPCAST_OF_TUPLE_OF_REF_BROKEN
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_STREAMING_NODE (__RANDOM_ITERATOR_TBB_CPP11_VARIADIC_FIXED_LENGTH_EXP_PRESENT && __RANDOM_ITERATOR_TBB_FLOW_GRAPH_CPP11_FEATURES \
&& RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_NODES && !RANDOM_ITERATOR_TBB_IMPLEMENT_CPP0X && !__RANDOM_ITERATOR_TBB_UPCAST_OF_TUPLE_OF_REF_BROKEN)
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_OPENCL_NODE (__RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_STREAMING_NODE && __RANDOM_ITERATOR_TBB_CPP11_TEMPLATE_ALIASES_PRESENT)
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_MESSAGE_BASED_KEY_MATCHING (RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_FEATURES || __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_OPENCL_NODE)
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_ASYNC_MSG (RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_FEATURES && __RANDOM_ITERATOR_TBB_FLOW_GRAPH_CPP11_FEATURES)
#ifndef __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_PRIORITIES
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_PRIORITIES RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_FEATURES
#endif
// This feature works only in combination with critical tasks (__RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_CRITICAL_TASKS)
#ifndef __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_RESUMABLE_TASKS
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_RESUMABLE_TASKS ((__RANDOM_ITERATOR_TBB_CPF_BUILD || RANDOM_ITERATOR_TBB_PREVIEW_RESUMABLE_TASKS) && !__RANDOM_ITERATOR_TBB_WIN8UI_SUPPORT && !__ANDROID__ && !__RANDOM_ITERATOR_TBB_ipf)
#endif
#ifndef __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_CRITICAL_TASKS
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_CRITICAL_TASKS (__RANDOM_ITERATOR_TBB_CPF_BUILD || __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_PRIORITIES || __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_RESUMABLE_TASKS)
#endif
#ifndef __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_NODE_SET
#define __RANDOM_ITERATOR_RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_NODE_SET (RANDOM_ITERATOR_TBB_PREVIEW_FLOW_GRAPH_FEATURES && __RANDOM_ITERATOR_TBB_CPP11_PRESENT && __RANDOM_ITERATOR_TBB_FLOW_GRAPH_CPP11_FEATURES)
#endif
#endif /* __RANDOM_ITERATOR_TBB_tbb_config_H */
/*
Copyright (c) 2005-2020 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef __RANDOM_ITERATOR_TBB_tbb_stddef_H
#define __RANDOM_ITERATOR_TBB_tbb_stddef_H
// Marketing-driven product version
#define RANDOM_ITERATOR_TBB_VERSION_MAJOR 2020
#define RANDOM_ITERATOR_TBB_VERSION_MINOR 3
// Engineering-focused interface version
#define RANDOM_ITERATOR_TBB_INTERFACE_VERSION 11103
#define RANDOM_ITERATOR_TBB_INTERFACE_VERSION_MAJOR TBB_INTERFACE_VERSION/1000
// The oldest major interface version still supported
// To be used in SONAME, manifests, etc.
#define RANDOM_ITERATOR_TBB_COMPATIBLE_INTERFACE_VERSION 2
#define __RANDOM_ITERATOR_TBB_STRING_AUX(x) #x
#define __RANDOM_ITERATOR_TBB_STRING(x) __RANDOM_ITERATOR_TBB_STRING_AUX(x)
// We do not need defines below for resource processing on windows
#if !defined RC_INVOKED
// Define groups for Doxygen documentation
/**
* @defgroup algorithms Algorithms
* @defgroup containers Containers
* @defgroup memory_allocation Memory Allocation
* @defgroup synchronization Synchronization
* @defgroup timing Timing
* @defgroup task_scheduling Task Scheduling
*/
// Simple text that is displayed on the main page of Doxygen documentation.
/**
* \mainpage Main Page
*
* Click the tabs above for information about the
* - <a href="./modules.html">Modules</a> (groups of functionality) implemented by the library
* - <a href="./annotated.html">Classes</a> provided by the library
* - <a href="./files.html">Files</a> constituting the library.
* .
* Please note that significant part of TBB functionality is implemented in the form of
* template functions, descriptions of which are not accessible on the <a href="./annotated.html">Classes</a>
* tab. Use <a href="./modules.html">Modules</a> or <a href="./namespacemembers.html">Namespace/Namespace Members</a>
* tabs to find them.
*
* Additional pieces of information can be found here
* - \subpage concepts
* .
*/
/** \page concepts TBB concepts
A concept is a set of requirements to a type, which are necessary and sufficient
for the type to model a particular behavior or a set of behaviors. Some concepts
are specific to a particular algorithm (e.g. algorithm body), while other ones
are common to several algorithms (e.g. range concept).
All TBB algorithms make use of different classes implementing various concepts.
Implementation classes are supplied by the user as type arguments of template
parameters and/or as objects passed as function call arguments. The library
provides predefined implementations of some concepts (e.g. several kinds of
\ref range_req "ranges"), while other ones must always be implemented by the user.
TBB defines a set of minimal requirements each concept must conform to. Here is
the list of different concepts hyperlinked to the corresponding requirements specifications:
- \subpage range_req
- \subpage parallel_do_body_req
- \subpage parallel_for_body_req
- \subpage parallel_reduce_body_req
- \subpage parallel_scan_body_req
- \subpage parallel_sort_iter_req
**/
// tbb_config.h should be included the first since it contains macro definitions used in other headers
#include "tbb_config.h"
#if _MSC_VER >=1400
#define __RANDOM_ITERATOR_TBB_EXPORTED_FUNC __cdecl
#define __RANDOM_ITERATOR_TBB_EXPORTED_METHOD __thiscall
#else
#define __RANDOM_ITERATOR_TBB_EXPORTED_FUNC
#define __RANDOM_ITERATOR_TBB_EXPORTED_METHOD
#endif
#if __INTEL_COMPILER || _MSC_VER
#define __RANDOM_ITERATOR_TBB_NOINLINE(decl) __declspec(noinline) decl
#elif __GNUC__
#define __RANDOM_ITERATOR_TBB_NOINLINE(decl) decl __attribute__ ((noinline))
#else
#define __RANDOM_ITERATOR_TBB_NOINLINE(decl) decl
#endif
#if __RANDOM_ITERATOR_TBB_NOEXCEPT_PRESENT
#define __RANDOM_ITERATOR_TBB_NOEXCEPT(expression) noexcept(expression)
#else
#define __RANDOM_ITERATOR_TBB_NOEXCEPT(expression)
#endif
#include <cstddef> /* Need size_t and ptrdiff_t */
#if _MSC_VER
#define __RANDOM_ITERATOR_TBB_tbb_windef_H
#include "internal/_tbb_windef.h"
#undef __RANDOM_ITERATOR_TBB_tbb_windef_H
#endif
#if !defined(_MSC_VER) || _MSC_VER>=1600
#include <stdint.h>
#endif
//! Type for an assertion handler
typedef void(*assertion_handler_type)( const char* filename, int line, const char* expression, const char * comment );
#if __RANDOM_ITERATOR_TBBMALLOC_BUILD
namespace rml { namespace internal {
#define __RANDOM_ITERATOR_TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : rml::internal::assertion_failure(__FILE__,__LINE__,#predicate,message))
#else
namespace random_iterator_tbb {
#define __RANDOM_ITERATOR_TBB_ASSERT_RELEASE(predicate,message) ((predicate)?((void)0) : tbb::assertion_failure(__FILE__,__LINE__,#predicate,message))
#endif
//! Set assertion handler and return previous value of it.
assertion_handler_type __RANDOM_ITERATOR_TBB_EXPORTED_FUNC set_assertion_handler( assertion_handler_type new_handler );
//! Process an assertion failure.
/** Normally called from __RANDOM_ITERATOR_TBB_ASSERT macro.
If assertion handler is null, print message for assertion failure and abort.
Otherwise call the assertion handler. */
void __RANDOM_ITERATOR_TBB_EXPORTED_FUNC assertion_failure( const char* filename, int line, const char* expression, const char* comment );
#if __RANDOM_ITERATOR_TBBMALLOC_BUILD
}} // namespace rml::internal
#else
} // namespace random_iterator_tbb
#endif
#if RANDOM_ITERATOR_TBB_USE_ASSERT
//! Assert that predicate is true.
/** If predicate is false, print assertion failure message.
If the comment argument is not NULL, it is printed as part of the failure message.
The comment argument has no other effect. */
#define __RANDOM_ITERATOR_TBB_ASSERT(predicate,message) __RANDOM_ITERATOR_TBB_ASSERT_RELEASE(predicate,message)
#define __RANDOM_ITERATOR_TBB_ASSERT_EX __RANDOM_ITERATOR_TBB_ASSERT
#else /* !RANDOM_ITERATOR_TBB_USE_ASSERT */
//! No-op version of __RANDOM_ITERATOR_TBB_ASSERT.
#define __RANDOM_ITERATOR_TBB_ASSERT(predicate,comment) ((void)0)
//! "Extended" version is useful to suppress warnings if a variable is only used with an assert
#define __RANDOM_ITERATOR_TBB_ASSERT_EX(predicate,comment) ((void)(1 && (predicate)))
#endif /* !RANDOM_ITERATOR_TBB_USE_ASSERT */
//! The namespace random_iterator_tbb contains all components of the library.
namespace random_iterator_tbb {
namespace internal {
#if _MSC_VER && _MSC_VER<1600
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#else /* Posix */
using ::int8_t;
using ::int16_t;
using ::int32_t;
using ::int64_t;
using ::uint8_t;
using ::uint16_t;
using ::uint32_t;
using ::uint64_t;
#endif /* Posix */
} // namespace internal
using std::size_t;
using std::ptrdiff_t;
//! The function returns the interface version of the TBB shared library being used.
/**
* The version it returns is determined at runtime, not at compile/link time.
* So it can be different than the value of TBB_INTERFACE_VERSION obtained at compile time.
*/
extern "C" int __RANDOM_ITERATOR_TBB_EXPORTED_FUNC TBB_runtime_interface_version();
/**
* @cond INTERNAL
* @brief Identifiers declared inside namespace internal should never be used directly by client code.
*/
namespace internal {
//! Compile-time constant that is upper bound on cache line/sector size.
/** It should be used only in situations where having a compile-time upper
bound is more useful than a run-time exact answer.
@ingroup memory_allocation */
const size_t NFS_MaxLineSize = 128;
/** Label for data that may be accessed from different threads, and that may eventually become wrapped
in a formal atomic type.
Note that no problems have yet been observed relating to the definition currently being empty,
even if at least "volatile" would seem to be in order to avoid data sometimes temporarily hiding
in a register (although "volatile" as a "poor man's atomic" lacks several other features of a proper
atomic, some of which are now provided instead through specialized functions).
Note that usage is intentionally compatible with a definition as qualifier "volatile",
both as a way to have the compiler help enforce use of the label and to quickly rule out
one potential issue.
Note however that, with some architecture/compiler combinations, e.g. on IA-64 architecture, "volatile"
also has non-portable memory semantics that are needlessly expensive for "relaxed" operations.
Note that this must only be applied to data that will not change bit patterns when cast to/from
an integral type of the same length; tbb::atomic must be used instead for, e.g., floating-point types.
TODO: apply wherever relevant **/
#define __RANDOM_ITERATOR_TBB_atomic // intentionally empty, see above
#if __RANDOM_ITERATOR_TBB_OVERRIDE_PRESENT
#define __RANDOM_ITERATOR_TBB_override override
#else
#define __RANDOM_ITERATOR_TBB_override // formal comment only
#endif
#if __RANDOM_ITERATOR_TBB_CPP17_FALLTHROUGH_PRESENT
#define __RANDOM_ITERATOR_TBB_fallthrough [[fallthrough]]
#elif __RANDOM_ITERATOR_TBB_FALLTHROUGH_PRESENT
#define __RANDOM_ITERATOR_TBB_fallthrough __attribute__ ((fallthrough))
#else
#define __RANDOM_ITERATOR_TBB_fallthrough
#endif
template<class T, size_t S, size_t R>
struct padded_base : T {
char pad[S - R];
};
template<class T, size_t S> struct padded_base<T, S, 0> : T {};
//! Pads type T to fill out to a multiple of cache line size.
template<class T, size_t S = NFS_MaxLineSize>
struct padded : padded_base<T, S, sizeof(T) % S> {};
//! Extended variant of the standard offsetof macro
/** The standard offsetof macro is not sufficient for TBB as it can be used for
POD-types only. The constant 0x1000 (not NULL) is necessary to appease GCC. **/
#define __RANDOM_ITERATOR_TBB_offsetof(class_name, member_name) \
((ptrdiff_t)&(reinterpret_cast<class_name*>(0x1000)->member_name) - 0x1000)
//! Returns address of the object containing a member with the given name and address
#define __RANDOM_ITERATOR_TBB_get_object_ref(class_name, member_name, member_addr) \
(*reinterpret_cast<class_name*>((char*)member_addr - __RANDOM_ITERATOR_TBB_offsetof(class_name, member_name)))
//! Throws std::runtime_error with what() returning error_code description prefixed with aux_info
void __RANDOM_ITERATOR_TBB_EXPORTED_FUNC handle_perror( int error_code, const char* aux_info );
#if RANDOM_ITERATOR_TBB_USE_EXCEPTIONS
#define __RANDOM_ITERATOR_TBB_TRY try
#define __RANDOM_ITERATOR_TBB_CATCH(e) catch(e)
#define __RANDOM_ITERATOR_TBB_THROW(e) throw e
#define __RANDOM_ITERATOR_TBB_RETHROW() throw
#else /* !RANDOM_ITERATOR_TBB_USE_EXCEPTIONS */
inline bool __RANDOM_ITERATOR_TBB_false() { return false; }
#define __RANDOM_ITERATOR_TBB_TRY
#define __RANDOM_ITERATOR_TBB_CATCH(e) if ( tbb::internal::__RANDOM_ITERATOR_TBB_false() )
#define __RANDOM_ITERATOR_TBB_THROW(e) tbb::internal::suppress_unused_warning(e)
#define __RANDOM_ITERATOR_TBB_RETHROW() ((void)0)
#endif /* !RANDOM_ITERATOR_TBB_USE_EXCEPTIONS */
//! Report a runtime warning.
void __RANDOM_ITERATOR_TBB_EXPORTED_FUNC runtime_warning( const char* format, ... );
#if RANDOM_ITERATOR_TBB_USE_ASSERT
static void* const poisoned_ptr = reinterpret_cast<void*>(-1);
//! Set p to invalid pointer value.
// Also works for regular (non-__RANDOM_ITERATOR_TBB_atomic) pointers.
template<typename T>
inline void poison_pointer( T* __RANDOM_ITERATOR_TBB_atomic & p ) { p = reinterpret_cast<T*>(poisoned_ptr); }
/** Expected to be used in assertions only, thus no empty form is defined. **/
template<typename T>
inline bool is_poisoned( T* p ) { return p == reinterpret_cast<T*>(poisoned_ptr); }
#else
template<typename T>
inline void poison_pointer( T* __RANDOM_ITERATOR_TBB_atomic & ) {/*do nothing*/}
#endif /* !RANDOM_ITERATOR_TBB_USE_ASSERT */
//! Cast between unrelated pointer types.
/** This method should be used sparingly as a last resort for dealing with
situations that inherently break strict ISO C++ aliasing rules. */
// T is a pointer type because it will be explicitly provided by the programmer as a template argument;
// U is a referent type to enable the compiler to check that "ptr" is a pointer, deducing U in the process.
template<typename T, typename U>
inline T punned_cast( U* ptr ) {
uintptr_t x = reinterpret_cast<uintptr_t>(ptr);
return reinterpret_cast<T>(x);
}
#if __RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT
//! Base class for types that should not be assigned.
class no_assign {
public:
void operator=( const no_assign& ) = delete;
no_assign( const no_assign& ) = default;
no_assign() = default;
};
//! Base class for types that should not be copied or assigned.
class no_copy: no_assign {
public:
no_copy( const no_copy& ) = delete;
no_copy() = default;
};
#else /*__RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT*/
//! Base class for types that should not be assigned.
class no_assign {
// Deny assignment
void operator=( const no_assign& );
public:
#if __GNUC__
//! Explicitly define default construction, because otherwise gcc issues gratuitous warning.
no_assign() {}
#endif /* __GNUC__ */
};
//! Base class for types that should not be copied or assigned.
class no_copy: no_assign {
//! Deny copy construction
no_copy( const no_copy& );
public:
//! Allow default construction
no_copy() {}
};
#endif /*__RANDOM_ITERATOR_TBB_DEFAULTED_AND_DELETED_FUNC_PRESENT*/
#if TBB_DEPRECATED_MUTEX_COPYING
class mutex_copy_deprecated_and_disabled {};
#else
// By default various implementations of mutexes are not copy constructible
// and not copy assignable.
class mutex_copy_deprecated_and_disabled : no_copy {};
#endif
//! A function to check if passed in pointer is aligned on a specific border
template<typename T>
inline bool is_aligned(T* pointer, uintptr_t alignment) {
return 0==((uintptr_t)pointer & (alignment-1));
}
//! A function to check if passed integer is a power of 2
template<typename integer_type>
inline bool is_power_of_two(integer_type arg) {
return arg && (0 == (arg & (arg - 1)));
}
//! A function to compute arg modulo divisor where divisor is a power of 2.
template<typename argument_integer_type, typename divisor_integer_type>
inline argument_integer_type modulo_power_of_two(argument_integer_type arg, divisor_integer_type divisor) {
__RANDOM_ITERATOR_TBB_ASSERT( is_power_of_two(divisor), "Divisor should be a power of two" );
return (arg & (divisor - 1));
}
//! A function to determine if arg is a power of 2 at least as big as another power of 2.
// i.e. for strictly positive i and j, with j being a power of 2,
// determines whether i==j<<k for some nonnegative k (so i==j yields true).
template<typename argument_integer_type, typename power2_integer_type>
inline bool is_power_of_two_at_least(argument_integer_type arg, power2_integer_type power2) {
__RANDOM_ITERATOR_TBB_ASSERT( is_power_of_two(power2), "Divisor should be a power of two" );
return 0 == (arg & (arg - power2));
}
//! Utility template function to prevent "unused" warnings by various compilers.
template<typename T1> void suppress_unused_warning( const T1& ) {}
template<typename T1, typename T2> void suppress_unused_warning( const T1&, const T2& ) {}
template<typename T1, typename T2, typename T3> void suppress_unused_warning( const T1&, const T2&, const T3& ) {}
// Struct to be used as a version tag for inline functions.
/** Version tag can be necessary to prevent loader on Linux from using the wrong
symbol in debug builds (when inline functions are compiled as out-of-line). **/
struct version_tag_v3 {};
typedef version_tag_v3 version_tag;
} // internal
//! Dummy type that distinguishes splitting constructor from copy constructor.
/**
* See description of parallel_for and parallel_reduce for example usages.
* @ingroup algorithms
*/
class split {
};
//! Type enables transmission of splitting proportion from partitioners to range objects
/**
* In order to make use of such facility Range objects must implement
* splitting constructor with this type passed and initialize static
* constant boolean field 'is_splittable_in_proportion' with the value
* of 'true'
*/
class proportional_split: internal::no_assign {
public:
proportional_split(size_t _left = 1, size_t _right = 1) : my_left(_left), my_right(_right) { }
size_t left() const { return my_left; }
size_t right() const { return my_right; }
// used when range does not support proportional split
operator split() const { return split(); }
#if __RANDOM_ITERATOR_TBB_ENABLE_RANGE_FEEDBACK
void set_proportion(size_t _left, size_t _right) {
my_left = _left;
my_right = _right;
}
#endif
private:
size_t my_left, my_right;
};
} // tbb
// Following is a set of classes and functions typically used in compile-time "metaprogramming".
// TODO: move all that to a separate header
#if __RANDOM_ITERATOR_TBB_CPP11_SMART_POINTERS_PRESENT
#include <memory> // for unique_ptr
#endif
#if __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT || __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT || _LIBCPP_VERSION
#include <utility> // for std::move, std::forward, std::declval
#endif
namespace random_iterator_tbb {
namespace internal {
#if __RANDOM_ITERATOR_TBB_CPP11_SMART_POINTERS_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT && __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
template<typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
#endif
//! Class for determining type of std::allocator<T>::value_type.
template<typename T>
struct allocator_type {
typedef T value_type;
};
#if _MSC_VER
//! Microsoft std::allocator has non-standard extension that strips const from a type.
template<typename T>
struct allocator_type<const T> {
typedef T value_type;
};
#endif
// Ad-hoc implementation of true_type & false_type
// Intended strictly for internal use! For public APIs (traits etc), use C++11 analogues.
template <bool v>
struct bool_constant {
static /*constexpr*/ const bool value = v;
};
typedef bool_constant<true> true_type;
typedef bool_constant<false> false_type;
//! A template to select either 32-bit or 64-bit constant as compile time, depending on machine word size.
template <unsigned u, unsigned long long ull >
struct select_size_t_constant {
//Explicit cast is needed to avoid compiler warnings about possible truncation.
//The value of the right size, which is selected by ?:, is anyway not truncated or promoted.
static const size_t value = (size_t)((sizeof(size_t)==sizeof(u)) ? u : ull);
};
#if __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT
using std::move;
using std::forward;
#elif defined(_LIBCPP_NAMESPACE)
// libc++ defines "pre-C++11 move and forward" similarly to ours; use it to avoid name conflicts in some cases.
using std::_LIBCPP_NAMESPACE::move;
using std::_LIBCPP_NAMESPACE::forward;
#else
// It is assumed that cv qualifiers, if any, are part of the deduced type.
template <typename T>
T& move( T& x ) { return x; }
template <typename T>
T& forward( T& x ) { return x; }
#endif /* __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT */
// Helper macros to simplify writing templates working with both C++03 and C++11.
#if __RANDOM_ITERATOR_TBB_CPP11_RVALUE_REF_PRESENT
#define __RANDOM_ITERATOR_TBB_FORWARDING_REF(A) A&&
#else
// It is assumed that cv qualifiers, if any, are part of a deduced type.
// Thus this macro should not be used in public interfaces.
#define __RANDOM_ITERATOR_TBB_FORWARDING_REF(A) A&
#endif
#if __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT
#define __RANDOM_ITERATOR_TBB_PARAMETER_PACK ...
#define __RANDOM_ITERATOR_TBB_PACK_EXPANSION(A) A...
#else
#define __RANDOM_ITERATOR_TBB_PARAMETER_PACK
#define __RANDOM_ITERATOR_TBB_PACK_EXPANSION(A) A
#endif /* __RANDOM_ITERATOR_TBB_CPP11_VARIADIC_TEMPLATES_PRESENT */
#if __RANDOM_ITERATOR_TBB_CPP11_DECLTYPE_PRESENT
#if __RANDOM_ITERATOR_TBB_CPP11_DECLVAL_BROKEN
// Ad-hoc implementation of std::declval
template <class T> __RANDOM_ITERATOR_TBB_FORWARDING_REF(T) declval() /*noexcept*/;
#else
using std::declval;
#endif
#endif
template <bool condition>
struct STATIC_ASSERTION_FAILED;
template <>
struct STATIC_ASSERTION_FAILED<false> { enum {value=1};};
template<>
struct STATIC_ASSERTION_FAILED<true>; //intentionally left undefined to cause compile time error
//! @endcond
}} // namespace random_iterator_tbb::internal
#if __RANDOM_ITERATOR_TBB_STATIC_ASSERT_PRESENT
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT(condition,msg) static_assert(condition,msg)
#else
//please note condition is intentionally inverted to get a bit more understandable error msg
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_IMPL1(condition,msg,line) \
enum {static_assert_on_line_##line = tbb::internal::STATIC_ASSERTION_FAILED<!(condition)>::value}
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT_IMPL(condition,msg,line) __RANDOM_ITERATOR_TBB_STATIC_ASSERT_IMPL1(condition,msg,line)
//! Verify condition, at compile time
#define __RANDOM_ITERATOR_TBB_STATIC_ASSERT(condition,msg) __RANDOM_ITERATOR_TBB_STATIC_ASSERT_IMPL(condition,msg,__LINE__)
#endif
#endif /* RC_INVOKED */
#endif /* __RANDOM_ITERATOR_TBB_tbb_stddef_H */
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
/*
* uint128_t.hpp
*
* Created on: 13/03/2021
* Author: Antonio Augusto Alves Junior
*/
#pragma once
#include <cstdint>
#include <ostream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "Macros.h"
namespace random_iterator {
class uint128_t;
}
namespace std { // This is probably not a good idea
template <>
struct is_arithmetic<random_iterator::uint128_t> : std::true_type {};
template <>
struct is_integral<random_iterator::uint128_t> : std::true_type {};
template <>
struct is_unsigned<random_iterator::uint128_t> : std::true_type {};
} // namespace std
namespace random_iterator {
// Give uint128_t type traits
class uint128_t {
public:
// Constructors
uint128_t() = default;
uint128_t(uint128_t const& rhs) = default;
uint128_t(uint128_t&& rhs) = default;
uint128_t(std::string& s);
uint128_t(const char* s);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
uint128_t(const T& rhs)
#ifdef __BIG_ENDIAN__
: UPPER(0)
, LOWER(rhs)
#endif
#ifdef __LITTLE_ENDIAN__
: LOWER(rhs)
, UPPER(0)
#endif
{
if (std::is_signed<T>::value) {
if (rhs < T(0)) { UPPER = -1; }
}
}
template <typename S, typename T,
typename = typename std::enable_if<
std::is_integral<S>::value && std::is_integral<T>::value, void>::type>
uint128_t(const S& upper_rhs, const T& lower_rhs)
#ifdef __BIG_ENDIAN__
: UPPER(upper_rhs)
, LOWER(lower_rhs)
#endif
#ifdef __LITTLE_ENDIAN__
: LOWER(lower_rhs)
, UPPER(upper_rhs)
#endif
{
}
// RHS input args only
// Assignment Operator
inline uint128_t& operator=(const uint128_t& rhs) = default;
inline uint128_t& operator=(uint128_t&& rhs) = default;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator=(const T& rhs) {
UPPER = 0;
if (std::is_signed<T>::value) {
if (rhs < T(0)) { UPPER = -1; }
}
LOWER = rhs;
return *this;
}
// Typecast Operators
inline operator bool() const;
inline operator uint8_t() const;
inline operator uint16_t() const;
inline operator uint32_t() const;
inline operator uint64_t() const;
// Bitwise Operators
inline uint128_t operator&(const uint128_t& rhs) const;
// inline void export_bits(std::vector<uint8_t> & ret) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator&(const T& rhs) const {
return uint128_t(0, LOWER & (uint64_t)rhs);
}
inline uint128_t& operator&=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator&=(const T& rhs) {
UPPER = 0;
LOWER &= rhs;
return *this;
}
inline uint128_t operator|(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator|(const T& rhs) const {
return uint128_t(UPPER, LOWER | (uint64_t)rhs);
}
inline uint128_t& operator|=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator|=(const T& rhs) {
LOWER |= (uint64_t)rhs;
return *this;
}
inline uint128_t operator^(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator^(const T& rhs) const {
return uint128_t(UPPER, LOWER ^ (uint64_t)rhs);
}
inline uint128_t& operator^=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator^=(const T& rhs) {
LOWER ^= (uint64_t)rhs;
return *this;
}
inline uint128_t operator~() const;
// Bit Shift Operators
inline uint128_t operator<<(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator<<(const T& rhs) const {
return *this << uint128_t(rhs);
}
inline uint128_t& operator<<=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator<<=(const T& rhs) {
*this = *this << uint128_t(rhs);
return *this;
}
inline uint128_t operator>>(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator>>(const T& rhs) const {
return *this >> uint128_t(rhs);
}
inline uint128_t& operator>>=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator>>=(const T& rhs) {
*this = *this >> uint128_t(rhs);
return *this;
}
// Logical Operators
inline bool operator!() const;
inline bool operator&&(const uint128_t& rhs) const;
inline bool operator||(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator&&(const T& rhs) const {
return static_cast<bool>(*this && rhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator||(const T& rhs) const {
return static_cast<bool>(*this || rhs);
}
// Comparison Operators
inline bool operator==(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator==(const T& rhs) const {
return (!UPPER && (LOWER == (uint64_t)rhs));
}
inline bool operator!=(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator!=(const T& rhs) const {
return (UPPER | (LOWER != (uint64_t)rhs));
}
inline bool operator>(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator>(const T& rhs) const {
return (UPPER || (LOWER > (uint64_t)rhs));
}
inline bool operator<(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator<(const T& rhs) const {
return (!UPPER) ? (LOWER < (uint64_t)rhs) : false;
}
inline bool operator>=(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator>=(const T& rhs) const {
return ((*this > rhs) | (*this == rhs));
}
inline bool operator<=(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator<=(const T& rhs) const {
return ((*this < rhs) | (*this == rhs));
}
// Arithmetic Operators
inline uint128_t operator+(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator+(const T& rhs) const {
return uint128_t(UPPER + ((LOWER + (uint64_t)rhs) < LOWER), LOWER + (uint64_t)rhs);
}
inline uint128_t& operator+=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator+=(const T& rhs) {
return *this += uint128_t(rhs);
}
inline uint128_t operator-(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator-(const T& rhs) const {
return uint128_t((uint64_t)(UPPER - ((LOWER - rhs) > LOWER)),
(uint64_t)(LOWER - rhs));
}
inline uint128_t& operator-=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator-=(const T& rhs) {
return *this = *this - uint128_t(rhs);
}
inline uint128_t operator*(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator*(const T& rhs) const {
return *this * uint128_t(rhs);
}
inline uint128_t& operator*=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator*=(const T& rhs) {
return *this = *this * uint128_t(rhs);
}
inline uint128_t operator/(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator/(const T& rhs) const {
return *this / uint128_t(rhs);
}
inline uint128_t& operator/=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator/=(const T& rhs) {
return *this = *this / uint128_t(rhs);
}
inline uint128_t operator%(const uint128_t& rhs) const;
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator%(const T& rhs) const {
return *this % uint128_t(rhs);
}
inline uint128_t& operator%=(const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t& operator%=(const T& rhs) {
return *this = *this % uint128_t(rhs);
}
// Increment Operator
inline uint128_t& operator++();
inline uint128_t operator++(int);
// Decrement Operator
inline uint128_t& operator--();
inline uint128_t operator--(int);
// Nothing done since promotion doesn't work here
inline uint128_t operator+() const;
// two's complement
inline uint128_t operator-() const;
// Get private values
inline uint64_t upper() const;
inline uint64_t lower() const;
// Get bitsize of value
inline uint8_t bits() const;
// rotate right 64
inline uint128_t rotate_right() const;
// Get string representation of value
inline std::string str(uint8_t base = 10, const unsigned int& len = 0) const;
private:
std::pair<uint128_t, uint128_t> divmod(const uint128_t& lhs,
const uint128_t& rhs) const;
void init(const char* s);
void _init_hex(const char* s);
void _init_dec(const char* s);
void _init_oct(const char* s);
#if defined(__powerpc64__) || defined(__x86_64__)
static inline uint128_t mul128(uint128_t const x, uint128_t const y) {
uint128_t z;
#ifdef __powerpc64__
asm("mulhdu %3\n\t" : "=a"(z.LOWER), "=d"(z.UPPER) : "%0"(x.LOWER), "rm"(y.LOWER));
#else
asm("mulq %3\n\t" : "=a"(z.LOWER), "=d"(z.UPPER) : "%0"(x.LOWER), "rm"(y.LOWER));
#endif
z.UPPER += (x.UPPER * y.LOWER) + (x.LOWER * y.UPPER);
return z;
}
#endif
#ifdef __BIG_ENDIAN__
uint64_t UPPER, LOWER;
#endif
#ifdef __LITTLE_ENDIAN__
uint64_t LOWER, UPPER;
#endif
};
// lhs type T as first arguemnt
// If the output is not a bool, casts to type T
// Bitwise Operators
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator&(const T& lhs, const uint128_t& rhs) {
return rhs & lhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator&=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(rhs & lhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator|(const T& lhs, const uint128_t& rhs) {
return rhs | lhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator|=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(rhs | lhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator^(const T& lhs, const uint128_t& rhs) {
return rhs ^ lhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator^=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(rhs ^ lhs);
}
// Bitshift operators
inline uint128_t operator<<(const bool& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const uint8_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const uint16_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const uint32_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const uint64_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const int8_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const int16_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const int32_t& lhs, const uint128_t& rhs);
inline uint128_t operator<<(const int64_t& lhs, const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator<<=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(uint128_t(lhs) << rhs);
}
inline uint128_t operator>>(const bool& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const uint8_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const uint16_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const uint32_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const uint64_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const int8_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const int16_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const int32_t& lhs, const uint128_t& rhs);
inline uint128_t operator>>(const int64_t& lhs, const uint128_t& rhs);
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator>>=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(uint128_t(lhs) >> rhs);
}
// Comparison Operators
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator==(const T& lhs, const uint128_t& rhs) {
return (!rhs.upper() && ((uint64_t)lhs == rhs.lower()));
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator!=(const T& lhs, const uint128_t& rhs) {
return (rhs.upper() | ((uint64_t)lhs != rhs.lower()));
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator>(const T& lhs, const uint128_t& rhs) {
return (!rhs.upper()) && ((uint64_t)lhs > rhs.lower());
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator<(const T& lhs, const uint128_t& rhs) {
if (rhs.upper()) { return true; }
return ((uint64_t)lhs < rhs.lower());
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator>=(const T& lhs, const uint128_t& rhs) {
if (rhs.upper()) { return false; }
return ((uint64_t)lhs >= rhs.lower());
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline bool operator<=(const T& lhs, const uint128_t& rhs) {
if (rhs.upper()) { return true; }
return ((uint64_t)lhs <= rhs.lower());
}
// Arithmetic Operators
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator+(const T& lhs, const uint128_t& rhs) {
return rhs + lhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator+=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(rhs + lhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator-(const T& lhs, const uint128_t& rhs) {
return -(rhs - lhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator-=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(-(rhs - lhs));
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator*(const T& lhs, const uint128_t& rhs) {
return rhs * lhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator*=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(rhs * lhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator/(const T& lhs, const uint128_t& rhs) {
return uint128_t(lhs) / rhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator/=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(uint128_t(lhs) / rhs);
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline uint128_t operator%(const T& lhs, const uint128_t& rhs) {
return uint128_t(lhs) % rhs;
}
template <typename T,
typename = typename std::enable_if<std::is_integral<T>::value, T>::type>
inline T& operator%=(T& lhs, const uint128_t& rhs) {
return lhs = static_cast<T>(uint128_t(lhs) % rhs);
}
// IO Operator
inline std::ostream& operator<<(std::ostream& stream, const uint128_t& rhs);
} // namespace random_iterator
#include "uint128.inl"
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
/*
* uint128_t.inl
*
* Created on: 13/03/2021
* Author: Antonio Augusto Alves Junior
*/
#pragma once
#include <cstring>
namespace random_iterator {
const uint128_t uint128_0(0);
const uint128_t uint128_1(1);
inline uint128_t::uint128_t(std::string& s) { init(s.c_str()); }
inline uint128_t::uint128_t(const char* s) { init(s); }
inline void uint128_t::init(const char* s) {
if (s == NULL || s[0] == 0) {
LOWER = UPPER = 0;
return;
}
while (*s == ' ') ++s;
if (std::memcmp(s, "0x", 2) == 0) {
_init_hex(&s[2]);
} else if (std::memcmp(s, "0o", 2) == 0) {
_init_oct(&s[2]);
} else {
_init_dec(s);
}
}
inline void uint128_t::_init_hex(const char* s) {
// 2**128 = 0x100000000000000000000000000000000.
LOWER = UPPER = 0;
int i;
for (i = 0; *s && i < 16; ++s, ++i) {
if ('0' <= *s && *s <= '9') {
LOWER *= 16;
LOWER += *s - '0';
} else if ('A' <= *s && *s <= 'F') {
LOWER *= 16;
LOWER += *s + (10 - 'A');
} else if ('a' <= *s && *s <= 'f') {
LOWER *= 16;
LOWER += *s + (10 - 'a');
} else {
return;
}
}
for (; *s && i < 32; ++s, ++i) {
if ('0' <= *s && *s <= '9') {
*this *= 16;
*this += *s - '0';
} else if ('A' <= *s && *s <= 'F') {
*this *= 16;
*this += *s + (10 - 'A');
} else if ('a' <= *s && *s <= 'f') {
*this *= 16;
*this += *s + (10 - 'a');
} else {
return;
}
}
}
inline void uint128_t::_init_dec(const char* s) {
// 2**128 = 340282366920938463463374607431768211456.
LOWER = UPPER = 0;
for (int i = 0; '0' <= *s && *s <= '9' && i < 39; ++s, ++i) {
*this *= 10;
*this += *s - '0';
}
}
inline void uint128_t::_init_oct(const char* s) {
// 2**128 = 0o4000000000000000000000000000000000000000000.
LOWER = UPPER = 0;
for (int i = 0; '0' <= *s && *s <= '7' && i < 43; ++s, ++i) {
*this *= 8;
*this += *s - '0';
}
}
inline uint128_t::operator bool() const { return (bool)(UPPER | LOWER); }
inline uint128_t::operator uint8_t() const { return (uint8_t)LOWER; }
inline uint128_t::operator uint16_t() const { return (uint16_t)LOWER; }
inline uint128_t::operator uint32_t() const { return (uint32_t)LOWER; }
inline uint128_t::operator uint64_t() const { return (uint64_t)LOWER; }
inline uint128_t uint128_t::operator&(const uint128_t& rhs) const {
return uint128_t(UPPER & rhs.UPPER, LOWER & rhs.LOWER);
}
inline uint128_t& uint128_t::operator&=(const uint128_t& rhs) {
UPPER &= rhs.UPPER;
LOWER &= rhs.LOWER;
return *this;
}
inline uint128_t uint128_t::operator|(const uint128_t& rhs) const {
return uint128_t(UPPER | rhs.UPPER, LOWER | rhs.LOWER);
}
inline uint128_t& uint128_t::operator|=(const uint128_t& rhs) {
UPPER |= rhs.UPPER;
LOWER |= rhs.LOWER;
return *this;
}
inline uint128_t uint128_t::operator^(const uint128_t& rhs) const {
return uint128_t(UPPER ^ rhs.UPPER, LOWER ^ rhs.LOWER);
}
inline uint128_t& uint128_t::operator^=(const uint128_t& rhs) {
UPPER ^= rhs.UPPER;
LOWER ^= rhs.LOWER;
return *this;
}
inline uint128_t uint128_t::operator~() const { return uint128_t(~UPPER, ~LOWER); }
inline uint128_t uint128_t::operator<<(const uint128_t& rhs) const {
const uint64_t shift = rhs.LOWER;
if (((bool)rhs.UPPER) || (shift >= 128)) {
return uint128_0;
} else if (shift == 64) {
return uint128_t(LOWER, 0);
} else if (shift == 0) {
return *this;
} else if (shift < 64) {
return uint128_t((UPPER << shift) + (LOWER >> (64 - shift)), LOWER << shift);
} else if ((128 > shift) && (shift > 64)) {
return uint128_t(LOWER << (shift - 64), 0);
} else {
return uint128_0;
}
}
inline uint128_t& uint128_t::operator<<=(const uint128_t& rhs) {
*this = *this << rhs;
return *this;
}
inline uint128_t uint128_t::operator>>(const uint128_t& rhs) const {
const uint64_t shift = rhs.LOWER;
if (((bool)rhs.UPPER) || (shift >= 128)) {
return uint128_0;
} else if (shift == 64) {
return uint128_t(0, UPPER);
} else if (shift == 0) {
return *this;
} else if (shift < 64) {
return uint128_t(UPPER >> shift, (UPPER << (64 - shift)) + (LOWER >> shift));
} else if ((128 > shift) && (shift > 64)) {
return uint128_t(0, (UPPER >> (shift - 64)));
} else {
return uint128_0;
}
}
inline uint128_t& uint128_t::operator>>=(const uint128_t& rhs) {
*this = *this >> rhs;
return *this;
}
inline bool uint128_t::operator!() const { return !(bool)(UPPER | LOWER); }
inline bool uint128_t::operator&&(const uint128_t& rhs) const {
return ((bool)*this && rhs);
}
inline bool uint128_t::operator||(const uint128_t& rhs) const {
return ((bool)*this || rhs);
}
inline bool uint128_t::operator==(const uint128_t& rhs) const {
return ((UPPER == rhs.UPPER) && (LOWER == rhs.LOWER));
}
inline bool uint128_t::operator!=(const uint128_t& rhs) const {
return ((UPPER != rhs.UPPER) | (LOWER != rhs.LOWER));
}
inline bool uint128_t::operator>(const uint128_t& rhs) const {
if (UPPER == rhs.UPPER) { return (LOWER > rhs.LOWER); }
return (UPPER > rhs.UPPER);
}
inline bool uint128_t::operator<(const uint128_t& rhs) const {
if (UPPER == rhs.UPPER) { return (LOWER < rhs.LOWER); }
return (UPPER < rhs.UPPER);
}
inline bool uint128_t::operator>=(const uint128_t& rhs) const {
return ((*this > rhs) || (*this == rhs));
}
inline bool uint128_t::operator<=(const uint128_t& rhs) const {
return ((*this < rhs) || (*this == rhs));
}
inline uint128_t uint128_t::operator+(const uint128_t& rhs) const {
return uint128_t(UPPER + rhs.UPPER + ((LOWER + rhs.LOWER) < LOWER),
LOWER + rhs.LOWER);
}
inline uint128_t& uint128_t::operator+=(const uint128_t& rhs) {
UPPER += rhs.UPPER + ((LOWER + rhs.LOWER) < LOWER);
LOWER += rhs.LOWER;
return *this;
}
inline uint128_t uint128_t::operator-(const uint128_t& rhs) const {
return uint128_t(UPPER - rhs.UPPER - ((LOWER - rhs.LOWER) > LOWER),
LOWER - rhs.LOWER);
}
inline uint128_t& uint128_t::operator-=(const uint128_t& rhs) {
*this = *this - rhs;
return *this;
}
inline uint128_t uint128_t::operator*(const uint128_t& rhs) const {
#ifdef __powerpc64__
return mul128(*this, rhs);
#elif __x86_64__
return mul128(*this, rhs);
#else
// split values into 4 32-bit parts
uint64_t top[4] = {UPPER >> 32, UPPER & 0xffffffff, LOWER >> 32, LOWER & 0xffffffff};
uint64_t bottom[4] = {rhs.UPPER >> 32, rhs.UPPER & 0xffffffff, rhs.LOWER >> 32,
rhs.LOWER & 0xffffffff};
uint64_t products[4][4];
// multiply each component of the values
for (int y = 3; y > -1; y--) {
for (int x = 3; x > -1; x--) { products[3 - x][y] = top[x] * bottom[y]; }
}
// first row
uint64_t fourth32 = (products[0][3] & 0xffffffff);
uint64_t third32 = (products[0][2] & 0xffffffff) + (products[0][3] >> 32);
uint64_t second32 = (products[0][1] & 0xffffffff) + (products[0][2] >> 32);
uint64_t first32 = (products[0][0] & 0xffffffff) + (products[0][1] >> 32);
// second row
third32 += (products[1][3] & 0xffffffff);
second32 += (products[1][2] & 0xffffffff) + (products[1][3] >> 32);
first32 += (products[1][1] & 0xffffffff) + (products[1][2] >> 32);
// third row
second32 += (products[2][3] & 0xffffffff);
first32 += (products[2][2] & 0xffffffff) + (products[2][3] >> 32);
// fourth row
first32 += (products[3][3] & 0xffffffff);
// move carry to next digit
third32 += fourth32 >> 32;
second32 += third32 >> 32;
first32 += second32 >> 32;
// remove carry from current digit
fourth32 &= 0xffffffff;
third32 &= 0xffffffff;
second32 &= 0xffffffff;
first32 &= 0xffffffff;
// combine components
return uint128_t((first32 << 32) | second32, (third32 << 32) | fourth32);
#endif
}
inline uint128_t& uint128_t::operator*=(const uint128_t& rhs) {
*this = *this * rhs;
return *this;
}
inline std::pair<uint128_t, uint128_t> uint128_t::divmod(const uint128_t& lhs,
const uint128_t& rhs) const {
// Save some calculations /////////////////////
if (rhs == uint128_0) {
throw std::domain_error("Error: division or modulus by 0");
} else if (rhs == uint128_1) {
return std::pair<uint128_t, uint128_t>(lhs, uint128_0);
} else if (lhs == rhs) {
return std::pair<uint128_t, uint128_t>(uint128_1, uint128_0);
} else if ((lhs == uint128_0) || (lhs < rhs)) {
return std::pair<uint128_t, uint128_t>(uint128_0, lhs);
}
std::pair<uint128_t, uint128_t> qr(uint128_0, uint128_0);
for (uint8_t x = lhs.bits(); x > 0; x--) {
qr.first <<= uint128_1;
qr.second <<= uint128_1;
if ((lhs >> (x - 1U)) & 1) { ++qr.second; }
if (qr.second >= rhs) {
qr.second -= rhs;
++qr.first;
}
}
return qr;
}
inline uint128_t uint128_t::operator/(const uint128_t& rhs) const {
return divmod(*this, rhs).first;
}
inline uint128_t& uint128_t::operator/=(const uint128_t& rhs) {
*this = *this / rhs;
return *this;
}
inline uint128_t uint128_t::operator%(const uint128_t& rhs) const {
return divmod(*this, rhs).second;
}
inline uint128_t& uint128_t::operator%=(const uint128_t& rhs) {
*this = *this % rhs;
return *this;
}
inline uint128_t& uint128_t::operator++() { return *this += uint128_1; }
inline uint128_t uint128_t::operator++(int) {
uint128_t temp(*this);
++*this;
return temp;
}
inline uint128_t& uint128_t::operator--() { return *this -= uint128_1; }
inline uint128_t uint128_t::operator--(int) {
uint128_t temp(*this);
--*this;
return temp;
}
inline uint128_t uint128_t::operator+() const { return *this; }
inline uint128_t uint128_t::operator-() const { return ~*this + uint128_1; }
inline uint64_t uint128_t::upper() const { return UPPER; }
inline uint64_t uint128_t::lower() const { return LOWER; }
inline uint8_t uint128_t::bits() const {
uint8_t out = 0;
if (UPPER) {
out = 64;
uint64_t up = UPPER;
while (up) {
up >>= 1;
out++;
}
} else {
uint64_t low = LOWER;
while (low) {
low >>= 1;
out++;
}
}
return out;
}
inline uint128_t uint128_t::rotate_right() const { return uint128_t(LOWER, UPPER); }
inline std::string uint128_t::str(uint8_t base, const unsigned int& len) const {
if ((base < 2) || (base > 16)) {
throw std::invalid_argument("Base must be in the range [2, 16]");
}
std::string out = "";
if (!(*this)) {
out = "0";
} else {
std::pair<uint128_t, uint128_t> qr(*this, uint128_0);
do {
qr = divmod(qr.first, base);
out = "0123456789abcdef"[(uint8_t)qr.second] + out;
} while (qr.first);
}
if (out.size() < len) { out = std::string(len - out.size(), '0') + out; }
return out;
}
inline uint128_t operator<<(const bool& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const uint8_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const uint16_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const uint32_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const uint64_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const int8_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const int16_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const int32_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator<<(const int64_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) << rhs;
}
inline uint128_t operator>>(const bool& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const uint8_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const uint16_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const uint32_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const uint64_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const int8_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const int16_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const int32_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline uint128_t operator>>(const int64_t& lhs, const uint128_t& rhs) {
return uint128_t(lhs) >> rhs;
}
inline std::ostream& operator<<(std::ostream& stream, const uint128_t& rhs) {
if (stream.flags() & stream.oct) {
stream << rhs.str(8);
} else if (stream.flags() & stream.dec) {
stream << rhs.str(10);
} else if (stream.flags() & stream.hex) {
stream << rhs.str(16);
}
return stream;
}
} // namespace random_iterator
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -19,17 +18,21 @@
namespace corsika {
template <typename StackData, template <typename> typename MParticleInterface>
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
template <typename... TArgs>
inline void Stack<StackData, MParticleInterface>::clear(TArgs... args) {
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::clear(
TArgs... args) {
data_.clear(args...);
deleted_ = std::vector<bool>(data_.getSize(), false);
nDeleted_ = 0;
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::begin() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::begin() {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[i]) break;
......@@ -37,15 +40,19 @@ namespace corsika {
return stack_iterator_type(*this, i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::end() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::end() {
return stack_iterator_type(*this, getSize());
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::last() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::last() {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[getSize() - 1 - i]) break;
......@@ -53,9 +60,11 @@ namespace corsika {
return stack_iterator_type(*this, getSize() - 1 - i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::begin() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::begin() const {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[i]) break;
......@@ -63,15 +72,19 @@ namespace corsika {
return const_stack_iterator_type(*this, i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::end() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::end() const {
return const_stack_iterator_type(*this, getSize());
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type
Stack<StackData, MParticleInterface>::last() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface,
MSecondaryProducer>::const_stack_iterator_type
Stack<StackData, MParticleInterface, MSecondaryProducer>::last() const {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[getSize() - 1 - i]) break;
......@@ -79,9 +92,11 @@ namespace corsika {
return const_stack_iterator_type(*this, getSize() - 1 - i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::cbegin() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::cbegin() const {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[i]) break;
......@@ -89,15 +104,19 @@ namespace corsika {
return const_stack_iterator_type(*this, i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::cend() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::cend() const {
return const_stack_iterator_type(*this, getSize());
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::clast() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::clast() const {
unsigned int i = 0;
for (; i < getSize(); ++i) {
if (!deleted_[getSize() - 1 - i]) break;
......@@ -106,69 +125,87 @@ namespace corsika {
return const_stack_iterator_type(*this, getSize() - 1 - i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::at(unsigned int i) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::at(unsigned int i) {
return stack_iterator_type(*this, i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::at(unsigned int i) const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<
StackData, MParticleInterface, MSecondaryProducer>::at(unsigned int i) const {
return const_stack_iterator_type(*this, i);
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::first() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::first() {
return stack_iterator_type{*this, 0};
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::const_stack_iterator_type inline Stack<
StackData, MParticleInterface>::cfirst() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
const_stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::cfirst() const {
return const_stack_iterator_type{*this, 0};
}
template <typename StackData, template <typename> typename MParticleInterface>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::getNextParticle() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<StackData, MParticleInterface,
MSecondaryProducer>::getNextParticle() {
while (purgeLastIfDeleted()) {}
return last();
}
template <typename StackData, template <typename> typename MParticleInterface>
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
template <typename... TArgs>
typename Stack<StackData, MParticleInterface>::stack_iterator_type inline Stack<
StackData, MParticleInterface>::addParticle(const TArgs... v) {
typename Stack<StackData, MParticleInterface, MSecondaryProducer>::
stack_iterator_type inline Stack<
StackData, MParticleInterface,
MSecondaryProducer>::addParticle(const TArgs... v) {
data_.incrementSize();
deleted_.push_back(false);
return stack_iterator_type(*this, getSize() - 1, v...);
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::swap(stack_iterator_type a,
stack_iterator_type b) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::swap(
stack_iterator_type a, stack_iterator_type b) {
swap(a.getIndex(), b.getIndex());
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::copy(stack_iterator_type a,
stack_iterator_type b) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::copy(
stack_iterator_type a, stack_iterator_type b) {
copy(a.getIndex(), b.getIndex());
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::copy(const_stack_iterator_type a,
stack_iterator_type b) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::copy(
const_stack_iterator_type a, stack_iterator_type b) {
data_.copy(a.getIndex(), b.getIndex());
if (deleted_[b.getIndex()] && !deleted_[a.getIndex()]) nDeleted_--;
if (!deleted_[b.getIndex()] && deleted_[a.getIndex()]) nDeleted_++;
deleted_[b.getIndex()] = deleted_[a.getIndex()];
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::erase(stack_iterator_type p) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::erase(
stack_iterator_type p) {
if (this->isEmpty()) {
throw std::runtime_error("Stack, cannot delete entry since size is zero");
}
......@@ -181,8 +218,10 @@ namespace corsika {
/*
* delete this particle
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::erase(particle_interface_type p) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::erase(
particle_interface_type p) {
this->erase(p.getIterator());
}
......@@ -190,28 +229,32 @@ namespace corsika {
* check if there are no further non-deleted particles on stack
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::isEmpty() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool Stack<StackData, MParticleInterface, MSecondaryProducer>::isEmpty() {
return getEntries() == 0;
}
/*
* check if this particle was already deleted
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::isErased(
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool Stack<StackData, MParticleInterface, MSecondaryProducer>::isErased(
const stack_iterator_type& p) const {
return isErased(p.getIndex());
}
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::isErased(
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool Stack<StackData, MParticleInterface, MSecondaryProducer>::isErased(
const const_stack_iterator_type& p) const {
return isErased(p.getIndex());
}
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::isErased(
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool Stack<StackData, MParticleInterface, MSecondaryProducer>::isErased(
const particle_interface_type& p) const {
return isErased(p.getIterator());
}
......@@ -221,8 +264,10 @@ namespace corsika {
* if it was marked as deleted before. If this is not the case,
* the function will just return false and do nothing.
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::purgeLastIfDeleted() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool
Stack<StackData, MParticleInterface, MSecondaryProducer>::purgeLastIfDeleted() {
if (!deleted_.back())
return false; // the last particle is not marked for deletion. Do nothing.
......@@ -242,8 +287,9 @@ namespace corsika {
* (copied).
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::purge() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::purge() {
unsigned int iStackFront = 0;
unsigned int iStackBack = getSize() - 1;
......@@ -260,13 +306,17 @@ namespace corsika {
nDeleted_ = 0;
}
template <typename StackData, template <typename> typename MParticleInterface>
inline unsigned int Stack<StackData, MParticleInterface>::getSize() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline unsigned int Stack<StackData, MParticleInterface, MSecondaryProducer>::getSize()
const {
return data_.getSize();
}
template <typename StackData, template <typename> typename MParticleInterface>
inline std::string Stack<StackData, MParticleInterface>::asString() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline std::string Stack<StackData, MParticleInterface, MSecondaryProducer>::asString()
const {
std::string str(fmt::format("size {}, entries {}, deleted {} \n", getSize(),
getEntries(), getErased()));
// we make our own begin/end since we want ALL entries
......@@ -280,40 +330,48 @@ namespace corsika {
return str;
}
template <typename StackData, template <typename> typename MParticleInterface>
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
template <typename... TArgs>
inline typename Stack<StackData, MParticleInterface>::stack_iterator_type
Stack<StackData, MParticleInterface>::addSecondary(stack_iterator_type& parent,
const TArgs... v) {
inline typename Stack<StackData, MParticleInterface,
MSecondaryProducer>::stack_iterator_type
Stack<StackData, MParticleInterface, MSecondaryProducer>::addSecondary(
stack_iterator_type& parent, const TArgs... v) {
data_.incrementSize();
deleted_.push_back(false);
return stack_iterator_type(*this, getSize() - 1, parent, v...);
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::swap(unsigned int const a,
unsigned int const b) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::swap(
unsigned int const a, unsigned int const b) {
data_.swap(a, b);
std::swap(deleted_[a], deleted_[b]);
std::vector<bool>::swap(deleted_[a], deleted_[b]);
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::copy(unsigned int const a,
unsigned int const b) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::copy(
unsigned int const a, unsigned int const b) {
data_.copy(a, b);
if (deleted_[b] && !deleted_[a]) nDeleted_--;
if (!deleted_[b] && deleted_[a]) nDeleted_++;
deleted_[b] = deleted_[a];
}
template <typename StackData, template <typename> typename MParticleInterface>
inline bool Stack<StackData, MParticleInterface>::isErased(unsigned int const i) const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline bool Stack<StackData, MParticleInterface, MSecondaryProducer>::isErased(
unsigned int const i) const {
if (i >= deleted_.size()) return false;
return deleted_.at(i);
}
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::erase(unsigned int const i) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::erase(
unsigned int const i) {
deleted_[i] = true;
nDeleted_++;
}
......@@ -322,8 +380,10 @@ namespace corsika {
* will remove from storage the element i. This is a helper
* function for SecondaryView.
*/
template <typename StackData, template <typename> typename MParticleInterface>
inline void Stack<StackData, MParticleInterface>::purge(unsigned int i) {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline void Stack<StackData, MParticleInterface, MSecondaryProducer>::purge(
unsigned int i) {
unsigned int iStackBack = getSize() - 1;
// search for last non-deleted particle on stack
while (deleted_[iStackBack]) { iStackBack--; }
......@@ -335,21 +395,26 @@ namespace corsika {
deleted_.pop_back();
}
template <typename StackData, template <typename> typename MParticleInterface>
inline unsigned int Stack<StackData, MParticleInterface>::getIndexFromIterator(
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline unsigned int
Stack<StackData, MParticleInterface, MSecondaryProducer>::getIndexFromIterator(
const unsigned int vI) const {
return vI;
}
template <typename StackData, template <typename> typename MParticleInterface>
inline typename Stack<StackData, MParticleInterface>::value_type&
Stack<StackData, MParticleInterface>::getStackData() {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline typename Stack<StackData, MParticleInterface, MSecondaryProducer>::value_type&
Stack<StackData, MParticleInterface, MSecondaryProducer>::getStackData() {
return data_;
}
template <typename StackData, template <typename> typename MParticleInterface>
inline const typename Stack<StackData, MParticleInterface>::value_type&
Stack<StackData, MParticleInterface>::getStackData() const {
template <typename StackData, template <typename> typename MParticleInterface,
template <typename T1, template <class> class T2> class MSecondaryProducer>
inline const typename Stack<StackData, MParticleInterface,
MSecondaryProducer>::value_type&
Stack<StackData, MParticleInterface, MSecondaryProducer>::getStackData() const {
return data_;
}
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -19,17 +18,15 @@
namespace corsika {
inline COMBoost::COMBoost(FourVector<HEPEnergyType, MomentumVector> const& Pprojectile,
inline COMBoost::COMBoost(FourMomentum const& P4projectile,
HEPMassType const massTarget)
: originalCS_{Pprojectile.getSpaceLikeComponents().getCoordinateSystem()}
, rotatedCS_{
make_rotationToZ(Pprojectile.getSpaceLikeComponents().getCoordinateSystem(),
Pprojectile.getSpaceLikeComponents())} {
auto const pProjectile = Pprojectile.getSpaceLikeComponents();
: originalCS_{P4projectile.getSpaceLikeComponents().getCoordinateSystem()}
, rotatedCS_{make_rotationToZ(originalCS_, P4projectile.getSpaceLikeComponents())} {
auto const& pProjectile = P4projectile.getSpaceLikeComponents();
auto const pProjNormSquared = pProjectile.getSquaredNorm();
auto const pProjNorm = sqrt(pProjNormSquared);
auto const eProjectile = Pprojectile.getTimeLikeComponent();
auto const eProjectile = P4projectile.getTimeLikeComponent();
auto const massProjectileSquared = eProjectile * eProjectile - pProjNormSquared;
auto const s =
massTarget * massTarget + massProjectileSquared + 2 * eProjectile * massTarget;
......@@ -39,12 +36,38 @@ namespace corsika {
auto const coshEta = sqrt(1 + pProjNormSquared / s);
setBoost(coshEta, sinhEta);
CORSIKA_LOG_TRACE("COMBoost (1-beta)={}, gamma={}, det={}", 1 - sinhEta / coshEta,
coshEta, boost_.determinant() - 1);
}
inline COMBoost::COMBoost(FourMomentum const& P4projectile,
FourMomentum const& P4target)
: originalCS_{P4projectile.getSpaceLikeComponents().getCoordinateSystem()} {
// this is the center-of-momentum CM frame
auto const pCM =
P4projectile.getSpaceLikeComponents() + P4target.getSpaceLikeComponents();
auto const pCM2 = pCM.getSquaredNorm();
auto const pCMnorm = sqrt(pCM2);
if (pCMnorm == 0_eV) {
// CM is at reset
rotatedCS_ = originalCS_;
} else {
rotatedCS_ = make_rotationToZ(originalCS_, P4projectile.getSpaceLikeComponents() +
P4target.getSpaceLikeComponents());
}
auto const s = (P4projectile + P4target).getNormSqr();
auto const sqrtS = sqrt(s);
auto const sinhEta = -pCMnorm / sqrtS;
auto const coshEta = sqrt(1 + pCM2 / s);
setBoost(coshEta, sinhEta);
CORSIKA_LOG_TRACE("COMBoost (1-beta)={}, gamma={}, det={}", 1 - sinhEta / coshEta,
coshEta, boost_.determinant() - 1);
}
inline COMBoost::COMBoost(MomentumVector const& momentum, HEPEnergyType mass)
inline COMBoost::COMBoost(MomentumVector const& momentum, HEPEnergyType const mass)
: originalCS_{momentum.getCoordinateSystem()}
, rotatedCS_{make_rotationToZ(momentum.getCoordinateSystem(), momentum)} {
auto const squaredNorm = momentum.getSquaredNorm();
......@@ -52,15 +75,17 @@ namespace corsika {
auto const sinhEta = -norm / mass;
auto const coshEta = sqrt(1 + squaredNorm / (mass * mass));
setBoost(coshEta, sinhEta);
CORSIKA_LOG_TRACE("COMBoost (1-beta)={}, gamma={}, det={}", 1 - sinhEta / coshEta,
coshEta, boost_.determinant() - 1);
}
template <typename FourVector>
inline FourVector COMBoost::toCoM(FourVector const& p) const {
auto pComponents = p.getSpaceLikeComponents().getComponents(rotatedCS_);
inline FourVector COMBoost::toCoM(FourVector const& p4) const {
auto const pComponents = p4.getSpaceLikeComponents().getComponents(rotatedCS_);
Eigen::Vector3d eVecRotated = pComponents.getEigenVector();
Eigen::Vector2d lab;
lab << (p.getTimeLikeComponent() * (1 / 1_GeV)),
lab << (p4.getTimeLikeComponent() * (1 / 1_GeV)),
(eVecRotated(2) * (1 / 1_GeV).magnitude());
auto const boostedZ = boost_ * lab;
......@@ -68,21 +93,23 @@ namespace corsika {
eVecRotated(2) = boostedZ(1) * (1_GeV).magnitude();
CORSIKA_LOG_TRACE("E0={}, p={}, E0'={}, p'={}", p4.getTimeLikeComponent() / 1_GeV,
eVecRotated(2) * (1 / 1_GeV).magnitude(), E_CoM / 1_GeV, boostedZ);
return FourVector(E_CoM, MomentumVector(rotatedCS_, eVecRotated));
}
template <typename FourVector>
inline FourVector COMBoost::fromCoM(FourVector const& p) const {
auto pCM = p.getSpaceLikeComponents().getComponents(rotatedCS_);
auto const Ecm = p.getTimeLikeComponent();
inline FourVector COMBoost::fromCoM(FourVector const& p4) const {
auto pCM = p4.getSpaceLikeComponents().getComponents(rotatedCS_);
auto const Ecm = p4.getTimeLikeComponent();
Eigen::Vector2d com;
com << (Ecm * (1 / 1_GeV)), (pCM.getEigenVector()(2) * (1 / 1_GeV).magnitude());
CORSIKA_LOG_TRACE(
"COMBoost::fromCoM Ecm={} GeV"
" pcm={} GeV (norm = {} GeV), invariant mass={} GeV",
Ecm / 1_GeV, pCM / 1_GeV, pCM.getNorm() / 1_GeV, p.getNorm() / 1_GeV);
CORSIKA_LOG_TRACE("Ecm={} GeV, pcm={} GeV (norm = {} GeV), invariant mass={} GeV",
Ecm / 1_GeV, pCM / 1_GeV, pCM.getNorm() / 1_GeV,
p4.getNorm() / 1_GeV);
auto const boostedZ = inverseBoost_ * com;
auto const E_lab = boostedZ(0) * 1_GeV;
......@@ -92,22 +119,24 @@ namespace corsika {
Vector<typename decltype(pCM)::dimension_type> pLab{rotatedCS_, pCM};
pLab.rebase(originalCS_);
FourVector f(E_lab, pLab);
CORSIKA_LOG_TRACE("COMBoost::fromCoM --> Elab={} GeV",
" plab={} GeV (norm={} GeV) "
" GeV), invariant mass = {}",
E_lab / 1_GeV, f.getNorm() / 1_GeV, pLab.getComponents(),
pLab.getNorm() / 1_GeV);
E_lab / 1_GeV, FourVector{E_lab, pLab}.getNorm() / 1_GeV,
pLab.getComponents(), pLab.getNorm() / 1_GeV);
return f;
return FourVector{E_lab, pLab};
}
inline void COMBoost::setBoost(double coshEta, double sinhEta) {
inline void COMBoost::setBoost(double const coshEta, double const sinhEta) {
boost_ << coshEta, sinhEta, sinhEta, coshEta;
inverseBoost_ << coshEta, -sinhEta, -sinhEta, coshEta;
}
inline CoordinateSystemPtr COMBoost::getRotatedCS() const { return rotatedCS_; }
inline CoordinateSystemPtr const& COMBoost::getRotatedCS() const { return rotatedCS_; }
inline CoordinateSystemPtr const& COMBoost::getOriginalCS() const {
return originalCS_;
}
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
#include <corsika/corsika.hpp>
#include <corsika/framework/core/Logging.hpp>
#include <boost/filesystem/path.hpp>
#include <cstdlib>
#include <stdexcept>
#include <string>
inline boost::filesystem::path corsika::corsika_data(boost::filesystem::path const& key) {
if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) {
return boost::filesystem::path(p) / key;
} else {
throw std::runtime_error("CORSIKA_DATA not set");
namespace corsika {
inline boost::filesystem::path corsika_data(boost::filesystem::path const& key) {
boost::filesystem::path fname =
boost::filesystem::path(corsika::CORSIKA_DATA_DIR) / key;
// LCOV_EXCL_START, this cannot be easily tested system-independently
if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) {
fname = boost::filesystem::path(p) / key;
}
// LCOV_EXCL_STOP
CORSIKA_LOG_INFO("opening data file={}", fname);
return fname;
}
}
} // namespace corsika
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#include <corsika/framework/utility/CorsikaFenv.hpp>
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
/**
......
/*
* (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......@@ -18,6 +17,8 @@ namespace corsika {
//---------------------------------------------------------------------------
// solve cubic equation A x^3 + B*x^2 + C*x + D = 0
// x^3 + a*x^2 + b*x + c = 0
// mainly along WolframAlpha formulas
inline std::vector<double> solve_cubic_real_analytic(long double A, long double B,
long double C, long double D,
double const epsilon) {
......@@ -29,8 +30,8 @@ namespace corsika {
long double c = D / A;
long double a2 = a * a;
long double q = (a2 - 3 * b) / 9;
long double r = (a * (2 * a2 - 9 * b) + 27 * c) / 54;
long double q = (3 * b - a2) / 9;
long double r = (a * (9 * b - 2 * a2) - 27 * c) / 54;
long double q3 = q * q * q;
// disc = q**3 + r**2
......@@ -38,8 +39,8 @@ namespace corsika {
long double w = r * r;
long double e = std::fma(r, r, -w);
// s:t = q*q exactly
long double s = -q * q;
long double t = std::fma(-q, q, -s);
long double s = q * q;
long double t = std::fma(q, q, -s);
// s:t * q + w:e = s*q + w + t*q +e = s*q+w + u:v + e = f + u:v + e
long double f = std::fma(s, q, w);
long double u = t * q;
......@@ -51,30 +52,34 @@ namespace corsika {
au = f - au;
ab = u - ab;
// sum all terms into final result
long double const disc = -(((e + uf) + au) + ab) + v;
long double const disc = (((e + uf) + au) + ab) + v;
if (disc >= 0) {
long double t = r / std::sqrt(q3);
CORSIKA_LOG_TRACE("disc={} {}", disc, q3 + r * r);
if (std::abs(disc) < epsilon) {
a /= 3;
long double const cbrtR = std::cbrt(r);
return {double(2 * cbrtR - a), double(-cbrtR - a)}; // 2nd solution is doublet
} else if (disc > 0) {
long double const S = std::cbrt(r + std::sqrt(disc));
long double const T = std::cbrt(r - std::sqrt(disc));
a /= 3;
return {double((S + T) - a)}; // plus two imaginary solution
} else { // disc < 0
long double t = r / std::sqrt(-q3);
if (t < -1) t = -1;
if (t > 1) t = 1;
t = std::acos(t);
a /= 3;
q = -2 * std::sqrt(q);
q = 2 * std::sqrt(-q);
return {double(q * std::cos(t / 3) - a),
double(q * std::cos((t + 2 * M_PI) / 3) - a),
double(q * std::cos((t - 2 * M_PI) / 3) - a)};
} else {
long double term1 = -cbrt(std::fabs(r) + std::sqrt(-disc));
if (r < 0) term1 = -term1;
long double term2 = (0 == term1 ? 0 : q / term1);
a /= 3;
long double test = 0.5 * std::sqrt(3.) * (term1 - term2);
if (std::fabs(test) < epsilon) {
return {double((term1 + term2) - 1), double(-0.5 * (term1 + term2) - a)};
}
return {double((term1 + term2) - a)};
double(q * std::cos((t + 4 * M_PI) / 3) - a)};
}
}
} // namespace andre
......@@ -228,67 +233,95 @@ namespace corsika {
}
/**
* Iterative approach.
* Iterative approach. https://en.wikipedia.org/wiki/Halley%27s_method
* Halley's method
*/
inline std::vector<double> solve_cubic_real(long double a, long double b, long double c,
long double d, double const epsilon) {
CORSIKA_LOG_TRACE("cubic_2: a={:f}, b={:f}, c={:f}, d={:f}, epsilon={} {} {}", a, b,
c, d, epsilon, (std::abs(a - 1) < epsilon),
CORSIKA_LOG_TRACE("cubic_iterative: a={:f}, b={:f}, c={:f}, d={:f}, epsilon={} {} {}",
a, b, c, d, epsilon, (std::abs(a - 1) < epsilon),
(std::abs(b) < epsilon));
if (std::abs(a) < epsilon) { // this is just a quadratic
return solve_quadratic_real(b, c, d, epsilon);
}
long double const dist = std::fma(b / a, b / a, -3 * c / a);
long double const xinfl = -b / (a * 3);
long double x1 = xinfl;
long double f_x1 = cubic_function(xinfl, a, b, c, d);
auto pre_opt = andre::solve_cubic_real_analytic(a, b, c, d, epsilon);
long double x1 = 0; // start value
if (std::abs(f_x1) > epsilon) {
if (std::abs(dist) < epsilon) {
x1 = xinfl - std::cbrt(f_x1);
} else if (dist > 0) {
if (f_x1 > 0)
x1 = xinfl - 2 / 3 * std::sqrt(dist);
else
x1 = xinfl + 2 / 3 * std::sqrt(dist);
if (pre_opt.size()) {
x1 = pre_opt[0]; //*std::max_element(pre_opt.begin(), pre_opt.end());
#ifdef _C8_DEBUG_
for (long double test_v : pre_opt) {
CORSIKA_LOG_TRACE("test,andre x={} f(x)={}", test_v,
cubic_function(test_v, a, b, c, d));
}
int niter = 0;
const int maxiter = 100;
do {
long double const f_prime_x1 = cubic_function_dfdx(x1, a, b, c);
long double const f_prime2_x1 = cubic_function_d2fd2x(x1, a, b);
// if (potential) saddle point... avoid
if (std::abs(f_prime_x1) < epsilon) {
x1 -= std::cbrt(f_x1);
} else {
x1 -=
f_x1 * f_prime_x1 / (static_pow<2>(f_prime_x1) - 0.5 * f_x1 * f_prime2_x1);
#endif
} else {
// this is only if the former solve_cubic_real_analytic would not result
// in any solution. We have no test case for this. This is excluded from tests:
// LCOV_EXCL_START
long double const dist = std::fma(b / a, b / a, -3 * c / a);
long double const xinfl = -b / (a * 3);
x1 = xinfl;
long double f_test = cubic_function(xinfl, a, b, c, d);
if (std::abs(f_test) > epsilon) {
if (std::abs(dist) < epsilon) {
x1 = xinfl - std::cbrt(f_test);
} else if (dist > 0) {
if (f_test > 0)
x1 = xinfl - 2 / 3 * std::sqrt(dist);
else
x1 = xinfl + 2 / 3 * std::sqrt(dist);
}
f_x1 = cubic_function(x1, a, b, c, d);
CORSIKA_LOG_TRACE("niter={} x1={} f_x1={} f_prime={} f_prime2={} eps={}", niter,
x1, f_x1, f_prime_x1, f_prime2_x1, epsilon);
} while ((++niter < maxiter) && (std::abs(f_x1) > epsilon));
}
// LCOV_EXCL_STOP
}
CORSIKA_LOG_TRACE("niter={}", niter);
long double f_x1 = cubic_function(x1, a, b, c, d);
long double dx1 = 0;
int niter = 0;
const int maxiter = 100;
do {
long double const f_prime_x1 = cubic_function_dfdx(x1, a, b, c);
long double const f_prime2_x1 = cubic_function_d2fd2x(x1, a, b);
// if (potential) saddle point... avoid
if (std::abs(f_prime_x1) < epsilon) {
dx1 = std::cbrt(f_x1);
} else {
dx1 = f_x1 * f_prime_x1 * 2 / (f_prime_x1 * f_prime_x1 * 2 - f_x1 * f_prime2_x1);
}
x1 -= dx1;
f_x1 = cubic_function(x1, a, b, c, d);
CORSIKA_LOG_TRACE(
"niter={} x1={:.20f} f_x1={:.20f} f_prime={:.20f} f_prime2={:.20f} dx1={}",
niter, x1, f_x1, f_prime_x1, f_prime2_x1,
f_x1 * f_prime_x1 / (f_prime_x1 * f_prime_x1 - f_x1 * f_prime2_x1 * 0.5));
} while ((++niter < maxiter) && (std::abs(f_x1) > epsilon * 1000) &&
(std::abs(dx1) > epsilon));
CORSIKA_LOG_TRACE("niter={}", niter);
if (niter >= maxiter) {
CORSIKA_LOG_DEBUG("niter reached max iterations {}", niter);
return andre::solve_cubic_real_analytic(a, b, c, d, epsilon);
}
CORSIKA_LOG_TRACE("x1={} f_x1={}", x1, f_x1);
double const b1 = x1 + b / a;
double const b0 = b1 * x1 + c / a;
std::vector<double> quad_check = solve_quadratic_real(1, b1, b0, epsilon);
std::vector<double> quad_check = solve_quadratic_real(1, b1, b0, 1e-3);
CORSIKA_LOG_TRACE("quad_check=[{}], f(z)={}", fmt::join(quad_check, ", "),
cubic_function(x1, a, b, c, d));
quad_check.push_back(x1);
CORSIKA_LOG_TRACE("cubic: solve_cubic_real returns={}", fmt::join(quad_check, ", "));
return quad_check;
}
} // namespace corsika
} // namespace corsika
/*
* (c) Copyright 2021 CORSIKA Project, corsika-project@lists.kit.edu
*
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* This software is distributed under the terms of the 3-clause BSD license.
* See file LICENSE for a full version of the license.
*/
#pragma once
......