Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
/*!
@file
Defines `boost::hana::common` and `boost::hana::common_t`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_COMMON_HPP
#define BOOST_HANA_CORE_COMMON_HPP
#include <boost/hana/fwd/core/common.hpp>
#include <boost/hana/concept/constant.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/when.hpp>
#include <boost/hana/detail/canonical_constant.hpp>
#include <boost/hana/detail/std_common_type.hpp>
#include <boost/hana/detail/void_t.hpp>
#include <type_traits>
BOOST_HANA_NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
// common
//////////////////////////////////////////////////////////////////////////
//! @cond
template <typename T, typename U, typename>
struct common : common<T, U, when<true>> { };
//! @endcond
template <typename T, typename U, bool condition>
struct common<T, U, when<condition>>
: detail::std_common_type<T, U>
{ };
template <typename T>
struct common<T, T> {
using type = T;
};
//////////////////////////////////////////////////////////////////////////
// has_common
//////////////////////////////////////////////////////////////////////////
template <typename T, typename U, typename>
struct has_common : std::false_type { };
template <typename T, typename U>
struct has_common<T, U, detail::void_t<typename common<T, U>::type>>
: std::true_type
{ };
//////////////////////////////////////////////////////////////////////////
// Provided common data types for Constants
//////////////////////////////////////////////////////////////////////////
namespace constant_detail {
//! @todo
//! This is an awful hack to avoid having
//! @code
//! common<integral_constant_tag<int>, integral_constant_tag<long>>
//! ==
//! CanonicalConstant<long>
//! @endcode
template <typename A, typename B, typename C>
struct which {
using type = detail::CanonicalConstant<C>;
};
template <template <typename ...> class A, typename T, typename U, typename C>
struct which<A<T>, A<U>, C> {
using type = A<C>;
};
}
template <typename A, typename B>
struct common<A, B, when<
hana::Constant<A>::value &&
hana::Constant<B>::value &&
has_common<typename A::value_type, typename B::value_type>::value
>> {
using type = typename constant_detail::which<
A, B,
typename common<typename A::value_type,
typename B::value_type>::type
>::type;
};
template <typename A, typename B>
struct common<A, B, when<
hana::Constant<A>::value &&
!hana::Constant<B>::value &&
has_common<typename A::value_type, B>::value
>> {
using type = typename common<typename A::value_type, B>::type;
};
template <typename A, typename B>
struct common<A, B, when<
!hana::Constant<A>::value &&
hana::Constant<B>::value &&
has_common<A, typename B::value_type>::value
>> {
using type = typename common<A, typename B::value_type>::type;
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_COMMON_HPP

View File

@@ -0,0 +1,32 @@
/*!
@file
Defines `boost::hana::default_` and `boost::hana::is_default`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_DEFAULT_HPP
#define BOOST_HANA_CORE_DEFAULT_HPP
#include <boost/hana/fwd/core/default.hpp>
#include <boost/hana/config.hpp>
#include <type_traits>
BOOST_HANA_NAMESPACE_BEGIN
template <typename Method, typename>
struct is_default : std::false_type { };
template <typename Method>
struct is_default<Method, decltype((void)
static_cast<default_>(*(Method*)0)
)>
: std::true_type
{ };
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_DEFAULT_HPP

View File

@@ -0,0 +1,18 @@
/*!
@file
Includes all the headers needed to setup tag-dispatching.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_DISPATCH_HPP
#define BOOST_HANA_CORE_DISPATCH_HPP
#include <boost/hana/core/tag_of.hpp>
#include <boost/hana/detail/dispatch_if.hpp>
#include <boost/hana/core/default.hpp>
#include <boost/hana/core/when.hpp>
#endif // !BOOST_HANA_CORE_DISPATCH_HPP

View File

@@ -0,0 +1,41 @@
/*!
@file
Defines `boost::hana::is_a` and `boost::hana::is_an`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_IS_A_HPP
#define BOOST_HANA_CORE_IS_A_HPP
#include <boost/hana/fwd/core/is_a.hpp>
#include <boost/hana/bool.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/tag_of.hpp>
#include <type_traits>
BOOST_HANA_NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
// is_a
//////////////////////////////////////////////////////////////////////////
template <typename DataType, typename T>
struct is_a_t<DataType, T>
: integral_constant<bool,
std::is_same<DataType, typename hana::tag_of<T>::type>::value
>
{ };
template <typename DataType>
struct is_a_t<DataType> {
template <typename T>
constexpr auto operator()(T const&) const
{ return hana::is_a<DataType, T>; }
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_IS_A_HPP

View File

@@ -0,0 +1,45 @@
/*!
@file
Defines `boost::hana::make`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_MAKE_HPP
#define BOOST_HANA_CORE_MAKE_HPP
#include <boost/hana/fwd/core/make.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/default.hpp>
#include <boost/hana/core/when.hpp>
BOOST_HANA_NAMESPACE_BEGIN
//! @cond
template <typename Datatype, typename>
struct make_impl : make_impl<Datatype, when<true>> { };
//! @endcond
template <typename Datatype, bool condition>
struct make_impl<Datatype, when<condition>> : default_ {
template <typename ...X>
static constexpr auto make_helper(int, X&& ...x)
-> decltype(Datatype(static_cast<X&&>(x)...))
{ return Datatype(static_cast<X&&>(x)...); }
template <typename ...X>
static constexpr auto make_helper(long, X&& ...) {
static_assert((sizeof...(X), false),
"there exists no constructor for the given data type");
}
template <typename ...X>
static constexpr decltype(auto) apply(X&& ...x)
{ return make_helper(int{}, static_cast<X&&>(x)...); }
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_MAKE_HPP

View File

@@ -0,0 +1,49 @@
/*!
@file
Defines `boost::hana::tag_of` and `boost::hana::tag_of_t`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_TAG_OF_HPP
#define BOOST_HANA_CORE_TAG_OF_HPP
#include <boost/hana/fwd/core/tag_of.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/when.hpp>
BOOST_HANA_NAMESPACE_BEGIN
//! @cond
template <typename T, typename>
struct tag_of : tag_of<T, when<true>> { };
//! @endcond
namespace core_detail {
template <typename ...>
struct is_valid { static constexpr bool value = true; };
}
template <typename T, bool condition>
struct tag_of<T, when<condition>> {
using type = T;
};
template <typename T>
struct tag_of<T, when<
core_detail::is_valid<typename T::hana_tag>::value
>> {
using type = typename T::hana_tag;
};
template <typename T> struct tag_of<T const> : tag_of<T> { };
template <typename T> struct tag_of<T volatile> : tag_of<T> { };
template <typename T> struct tag_of<T const volatile> : tag_of<T> { };
template <typename T> struct tag_of<T&> : tag_of<T> { };
template <typename T> struct tag_of<T&&> : tag_of<T> { };
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_TAG_OF_HPP

View File

@@ -0,0 +1,194 @@
/*!
@file
Defines `boost::hana::to` and related utilities.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_TO_HPP
#define BOOST_HANA_CORE_TO_HPP
#include <boost/hana/fwd/core/to.hpp>
#include <boost/hana/concept/constant.hpp>
#include <boost/hana/concept/foldable.hpp>
#include <boost/hana/concept/sequence.hpp>
#include <boost/hana/config.hpp>
#include <boost/hana/core/common.hpp>
#include <boost/hana/core/dispatch.hpp>
#include <boost/hana/core/make.hpp>
#include <boost/hana/detail/wrong.hpp>
#include <boost/hana/unpack.hpp>
#include <boost/hana/value.hpp>
#include <type_traits>
#include <utility>
BOOST_HANA_NAMESPACE_BEGIN
//////////////////////////////////////////////////////////////////////////
// to
//////////////////////////////////////////////////////////////////////////
//! @cond
template <typename To, typename From, typename>
struct to_impl : to_impl<To, From, when<true>> { };
//! @endcond
namespace convert_detail {
struct no_conversion { };
template <typename ...>
struct is_valid { static constexpr bool value = true; };
}
template <typename To, typename From, bool condition>
struct to_impl<To, From, when<condition>> : convert_detail::no_conversion {
template <typename X>
static constexpr auto apply(X const&) {
static_assert(detail::wrong<to_impl<To, From>, X>{},
"no conversion is available between the provided types");
}
};
template <typename To, typename From>
struct to_impl<To, From, when<convert_detail::is_valid<
decltype(static_cast<To>(std::declval<From>()))
>::value>> {
template <typename X>
static constexpr To apply(X&& x)
{ return static_cast<To>(static_cast<X&&>(x)); }
};
template <typename To>
struct to_impl<To, To> : embedding<> {
template <typename X>
static constexpr X apply(X&& x)
{ return static_cast<X&&>(x); }
};
//! @cond
template <typename To>
template <typename X>
constexpr decltype(auto) to_t<To>::operator()(X&& x) const {
using From = typename hana::tag_of<X>::type;
return to_impl<To, From>::apply(static_cast<X&&>(x));
}
//! @endcond
#define BOOST_HANA_DEFINE_EMBEDDING_IMPL(TO, FROM) \
template <> \
struct to_impl<TO, FROM> : embedding<> \
{ static constexpr TO apply(FROM x) { return x; } } \
/**/
BOOST_HANA_DEFINE_EMBEDDING_IMPL(long double, double);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(long double, float);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(double , float);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long long, signed long);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long long, signed int);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long long, signed short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long long, signed char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long , signed int);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long , signed short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed long , signed char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed int , signed short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed int , signed char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(signed short , signed char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long long, unsigned long);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long long, unsigned int);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long long, unsigned short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long long, unsigned char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long , unsigned int);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long , unsigned short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned long , unsigned char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned int , unsigned short);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned int , unsigned char);
BOOST_HANA_DEFINE_EMBEDDING_IMPL(unsigned short , unsigned char);
#undef BOOST_HANA_DEFINE_EMBEDDING_IMPL
namespace detail {
template <typename T>
struct copy_char_signedness {
using type = typename std::conditional<std::is_signed<char>::value,
std::make_signed<T>, std::make_unsigned<T>
>::type::type;
};
}
// If `char` is signed, we define an embedding from `char` to any signed
// integral type. Otherwise, we define one from `char` to any unsigned
// integral type.
#define BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL(TO) \
template <> \
struct to_impl<detail::copy_char_signedness<TO>::type, char> \
: embedding<> \
{ \
static constexpr detail::copy_char_signedness<TO>::type \
apply(char x) \
{ return x; } \
} \
/**/
BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL(long long);
BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL(long);
BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL(int);
BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL(short);
#undef BOOST_HANA_DEFINE_CHAR_EMBEDDING_IMPL
template <typename T>
struct to_impl<T*, decltype(nullptr)> : embedding<> {
static constexpr T* apply(decltype(nullptr)) { return nullptr; }
};
//////////////////////////////////////////////////////////////////////////
// is_convertible
//////////////////////////////////////////////////////////////////////////
template <typename From, typename To, typename>
struct is_convertible : std::true_type { };
template <typename From, typename To>
struct is_convertible<From, To, decltype((void)
static_cast<convert_detail::no_conversion>(*(to_impl<To, From>*)0)
)> : std::false_type { };
//////////////////////////////////////////////////////////////////////////
// is_embedded
//////////////////////////////////////////////////////////////////////////
template <typename From, typename To, typename>
struct is_embedded : std::false_type { };
template <typename From, typename To>
struct is_embedded<From, To, decltype((void)
static_cast<embedding<true>>(*(to_impl<To, From>*)0)
)> : std::true_type { };
//////////////////////////////////////////////////////////////////////////
// Conversion for Constants
//////////////////////////////////////////////////////////////////////////
template <typename To, typename From>
struct to_impl<To, From, when<
hana::Constant<From>::value &&
is_convertible<typename From::value_type, To>::value
>> : embedding<is_embedded<typename From::value_type, To>::value> {
template <typename X>
static constexpr decltype(auto) apply(X const&)
{ return hana::to<To>(hana::value<X>()); }
};
//////////////////////////////////////////////////////////////////////////
// Foldable -> Sequence
//////////////////////////////////////////////////////////////////////////
template <typename S, typename F>
struct to_impl<S, F, when<
hana::Sequence<S>::value &&
hana::Foldable<F>::value
>> : embedding<Sequence<F>::value> {
template <typename Xs>
static constexpr decltype(auto) apply(Xs&& xs)
{ return hana::unpack(static_cast<Xs&&>(xs), hana::make<S>); }
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_CORE_TO_HPP

View File

@@ -0,0 +1,15 @@
/*!
@file
Defines `boost::hana::when` and `boost::hana::when_valid`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_CORE_WHEN_HPP
#define BOOST_HANA_CORE_WHEN_HPP
#include <boost/hana/fwd/core/when.hpp>
#endif // !BOOST_HANA_CORE_WHEN_HPP