/usr/local/lib64/python3.6/site-packages/torch/include/c10/util
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/c10/util/variant.h (95182B)
// MPark.Variant
//
// Copyright Michael Park, 2015-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)
//
// From https://github.com/mpark/variant
//
// C10
// - Move to `c10` namespace.
// - Rename namespace `detail` to `detail_`, to not conflict with existing
// c10 implementations in `detail` namespace.
// - In two functions, the template name reference `I` is changed to
// `detail_::best_match
::value` to work around gcc 7.3.1 bug.
// However, this workaround also limits the use cases of `c10::variant`.
// Please see NOTE [gcc 7.3.1 bug workaround] for details.
// - The following code is moved to `c10/util/in_place.h`:
// ```
// struct in_place_t { explicit in_place_t() = default; };
//
// template
// struct in_place_index_t { explicit in_place_index_t() = default; };
//
// template
// struct in_place_type_t { explicit in_place_type_t() = default; };
//
// constexpr in_place_t in_place{};
// ```
// so that they can also be used in `c10/util/Optional.h`.
#ifndef C10_UTIL_VARIANT_H_
#define C10_UTIL_VARIANT_H_
/*
variant synopsis
namespace std {
// 20.7.2, class template variant
template
class variant {
public:
// 20.7.2.1, constructors
constexpr variant() noexcept(see below);
variant(const variant&);
variant(variant&&) noexcept(see below);
template constexpr variant(T&&) noexcept(see below);
template
constexpr explicit variant(in_place_type_t, Args&&...);
template
constexpr explicit variant(
in_place_type_t, initializer_list, Args&&...);
template
constexpr explicit variant(in_place_index_t, Args&&...);
template
constexpr explicit variant(
in_place_index_t, initializer_list, Args&&...);
// 20.7.2.2, destructor
~variant();
// 20.7.2.3, assignment
variant& operator=(const variant&);
variant& operator=(variant&&) noexcept(see below);
template variant& operator=(T&&) noexcept(see below);
// 20.7.2.4, modifiers
template
T& emplace(Args&&...);
template
T& emplace(initializer_list, Args&&...);
template
variant_alternative& emplace(Args&&...);
template
variant_alternative& emplace(initializer_list, Args&&...);
// 20.7.2.5, value status
constexpr bool valueless_by_exception() const noexcept;
constexpr size_t index() const noexcept;
// 20.7.2.6, swap
void swap(variant&) noexcept(see below);
};
// 20.7.3, variant helper classes
template struct variant_size; // undefined
template
constexpr size_t variant_size_v = variant_size::value;
template struct variant_size;
template struct variant_size;
template struct variant_size;
template
struct variant_size>;
template struct variant_alternative; // undefined
template
using variant_alternative_t = typename variant_alternative::type;
template struct variant_alternative;
template struct variant_alternative;
template struct variant_alternative;
template
struct variant_alternative>;
constexpr size_t variant_npos = -1;
// 20.7.4, value access
template
constexpr bool holds_alternative(const variant&) noexcept;
template
constexpr variant_alternative_t>&
get(variant&);
template
constexpr variant_alternative_t>&&
get(variant&&);
template
constexpr variant_alternative_t> const&
get(const variant&);
template
constexpr variant_alternative_t> const&&
get(const variant&&);
template
constexpr T& get(variant&);
template
constexpr T&& get(variant&&);
template
constexpr const T& get(const variant&);
template
constexpr const T&& get(const variant&&);
template
constexpr add_pointer_t>>
get_if(variant*) noexcept;
template
constexpr add_pointer_t>>
get_if(const variant*) noexcept;
template
constexpr add_pointer_t
get_if(variant*) noexcept;
template
constexpr add_pointer_t
get_if(const variant*) noexcept;
// 20.7.5, relational operators
template
constexpr bool operator==(const variant&, const variant&);
template
constexpr bool operator!=(const variant&, const variant&);
template
constexpr bool operator<(const variant&, const variant&);
template
constexpr bool operator>(const variant&, const variant&);
template
constexpr bool operator<=(const variant&, const variant&);
template
constexpr bool operator>=(const variant&, const variant&);
// 20.7.6, visitation
template
constexpr see below visit(Visitor&&, Variants&&...);
// 20.7.7, class monostate
struct monostate;
// 20.7.8, monostate relational operators
constexpr bool operator<(monostate, monostate) noexcept;
constexpr bool operator>(monostate, monostate) noexcept;
constexpr bool operator<=(monostate, monostate) noexcept;
constexpr bool operator>=(monostate, monostate) noexcept;
constexpr bool operator==(monostate, monostate) noexcept;
constexpr bool operator!=(monostate, monostate) noexcept;
// 20.7.9, specialized algorithms
template
void swap(variant&, variant&) noexcept(see below);
// 20.7.10, class bad_variant_access
class bad_variant_access;
// 20.7.11, hash support
template struct hash;
template struct hash>;
template <> struct hash;
} // namespace std
*/
#include
#include
#include
#include
#include
#include
#include
// MPark.Variant
//
// Copyright Michael Park, 2015-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 MPARK_CONFIG_HPP
#define MPARK_CONFIG_HPP
// MSVC 2015 Update 3.
#if __cplusplus < 201103L && (!defined(_MSC_VER) || _MSC_FULL_VER < 190024210)
#error "MPark.Variant requires C++11 support."
#endif
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_include
#define __has_include(x) 0
#endif
#ifndef __has_feature
#define __has_feature(x) 0
#endif
#if __has_attribute(always_inline) || defined(__GNUC__)
#define MPARK_ALWAYS_INLINE __attribute__((__always_inline__)) inline
#elif defined(_MSC_VER)
#define MPARK_ALWAYS_INLINE __forceinline
#else
#define MPARK_ALWAYS_INLINE inline
#endif
#if __has_builtin(__builtin_addressof) || \
(defined(__GNUC__) && __GNUC__ >= 7) || defined(_MSC_VER)
#define MPARK_BUILTIN_ADDRESSOF
#endif
#if __has_builtin(__builtin_unreachable) || defined(__GNUC__)
#define MPARK_BUILTIN_UNREACHABLE __builtin_unreachable()
#elif defined(_MSC_VER)
#define MPARK_BUILTIN_UNREACHABLE __assume(false)
#else
#define MPARK_BUILTIN_UNREACHABLE
#endif
#if __has_builtin(__type_pack_element)
#define MPARK_TYPE_PACK_ELEMENT
#endif
#if defined(__cpp_constexpr) && __cpp_constexpr >= 200704 && \
!(defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 9)
#define MPARK_CPP11_CONSTEXPR
#endif
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
#define MPARK_CPP14_CONSTEXPR
#endif
#if __has_feature(cxx_exceptions) || defined(__cpp_exceptions) || \
(defined(_MSC_VER) && defined(_CPPUNWIND))
#define MPARK_EXCEPTIONS
#endif
#if defined(__cpp_generic_lambdas) || defined(_MSC_VER)
#define MPARK_GENERIC_LAMBDAS
#endif
#if defined(__cpp_lib_integer_sequence)
#define MPARK_INTEGER_SEQUENCE
#endif
#if defined(__cpp_return_type_deduction) || defined(_MSC_VER)
#define MPARK_RETURN_TYPE_DEDUCTION
#endif
#if defined(__cpp_lib_transparent_operators) || defined(_MSC_VER)
#define MPARK_TRANSPARENT_OPERATORS
#endif
#if defined(__cpp_variable_templates) || defined(_MSC_VER)
#define MPARK_VARIABLE_TEMPLATES
#endif
#if !defined(__GLIBCXX__) || __has_include() // >= libstdc++-5
#define MPARK_TRIVIALITY_TYPE_TRAITS
#define MPARK_INCOMPLETE_TYPE_TRAITS
#endif
#endif // MPARK_CONFIG_HPP
// MPark.Variant
//
// Copyright Michael Park, 2015-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 MPARK_IN_PLACE_HPP
#define MPARK_IN_PLACE_HPP
#include
#include
namespace c10 {
#ifdef MPARK_VARIABLE_TEMPLATES
template
constexpr in_place_index_t in_place_index{};
template
constexpr in_place_type_t in_place_type{};
#endif
} // namespace c10
#endif // MPARK_IN_PLACE_HPP
// MPark.Variant
//
// Copyright Michael Park, 2015-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 MPARK_LIB_HPP
#define MPARK_LIB_HPP
#include
#include
#include
#include
#define MPARK_RETURN(...) \
noexcept(noexcept(__VA_ARGS__))->decltype(__VA_ARGS__) { \
return __VA_ARGS__; \
}
namespace c10 {
namespace lib {
template
struct identity {
using type = T;
};
inline namespace cpp14 {
template
struct array {
constexpr const T& operator[](std::size_t index) const {
return data[index];
}
T data[N == 0 ? 1 : N];
};
template
using add_pointer_t = typename std::add_pointer::type;
template
using common_type_t = typename std::common_type::type;
template
using decay_t = typename std::decay::type;
template
using enable_if_t = typename std::enable_if::type;
template
using remove_const_t = typename std::remove_const::type;
template
using remove_reference_t = typename std::remove_reference::type;
template
inline constexpr T&& forward(remove_reference_t& t) noexcept {
return static_cast(t);
}
template
inline constexpr T&& forward(remove_reference_t&& t) noexcept {
static_assert(
!std::is_lvalue_reference::value,
"can not forward an rvalue as an lvalue");
return static_cast(t);
}
template
inline constexpr remove_reference_t&& move(T&& t) noexcept {
return static_cast&&>(t);
}
#ifdef MPARK_INTEGER_SEQUENCE
using std::index_sequence;
using std::index_sequence_for;
using std::integer_sequence;
using std::make_index_sequence;
#else
template
struct integer_sequence {
using value_type = T;
static constexpr std::size_t size() noexcept {
return sizeof...(Is);
}
};
template
using index_sequence = integer_sequence;
template
struct make_index_sequence_concat;
template
struct make_index_sequence_concat<
index_sequence,
index_sequence>
: identity> {};
template
struct make_index_sequence_impl;
template
using make_index_sequence = typename make_index_sequence_impl::type;
template
struct make_index_sequence_impl : make_index_sequence_concat<
make_index_sequence,
make_index_sequence> {};
template <>
struct make_index_sequence_impl<0> : identity> {};
template <>
struct make_index_sequence_impl<1> : identity> {};
template
using index_sequence_for = make_index_sequence;
#endif
//
#ifdef MPARK_TRANSPARENT_OPERATORS
using equal_to = std::equal_to<>;
#else
struct equal_to {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) == lib::forward(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using not_equal_to = std::not_equal_to<>;
#else
struct not_equal_to {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) != lib::forward(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using less = std::less<>;
#else
struct less {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) < lib::forward(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using greater = std::greater<>;
#else
struct greater {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) > lib::forward(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using less_equal = std::less_equal<>;
#else
struct less_equal {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) <= lib::forward(rhs))
};
#endif
#ifdef MPARK_TRANSPARENT_OPERATORS
using greater_equal = std::greater_equal<>;
#else
struct greater_equal {
template
inline constexpr auto operator()(Lhs&& lhs, Rhs&& rhs) const
MPARK_RETURN(lib::forward(lhs) >= lib::forward(rhs))
};
#endif
} // namespace cpp14
inline namespace cpp17 {
//
template
using bool_constant = std::integral_constant;
template
struct voider : identity {};
template
using void_t = typename voider::type;
namespace detail_ {
namespace swappable {
using std::swap;
template
struct is_swappable {
private:
template <
typename U,
typename = decltype(swap(std::declval(), std::declval()))>
inline static std::true_type test(int);
template
inline static std::false_type test(...);
public:
static constexpr bool value = decltype(test(0))::value;
};
template
struct is_nothrow_swappable {
static constexpr bool value =
noexcept(swap(std::declval(), std::declval()));
};
template
struct is_nothrow_swappable : std::false_type {};
} // namespace swappable
} // namespace detail_
using detail_::swappable::is_swappable;
template
using is_nothrow_swappable =
detail_::swappable::is_nothrow_swappable::value, T>;
//
namespace detail_ {
template
struct is_reference_wrapper : std::false_type {};
template
struct is_reference_wrapper> : std::true_type {};
template
struct Invoke;
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmf, Arg&& arg, Args&&... args)
MPARK_RETURN((lib::forward(arg).*pmf)(lib::forward(args)...))
};
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmf, Arg&& arg, Args&&... args)
MPARK_RETURN(
(lib::forward(arg).get().*pmf)(lib::forward(args)...))
};
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmf, Arg&& arg, Args&&... args)
MPARK_RETURN(
((*lib::forward(arg)).*pmf)(lib::forward(args)...))
};
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmo, Arg&& arg)
MPARK_RETURN(lib::forward(arg).*pmo)
};
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmo, Arg&& arg)
MPARK_RETURN(lib::forward(arg).get().*pmo)
};
template <>
struct Invoke {
template
inline static constexpr auto invoke(R T::*pmo, Arg&& arg)
MPARK_RETURN((*lib::forward(arg)).*pmo)
};
template
inline constexpr auto invoke(R T::*f, Arg&& arg, Args&&... args) MPARK_RETURN(
Invoke<
std::is_function::value,
(std::is_base_of>::value ? 0
: is_reference_wrapper>::value ? 1
: 2)>::
invoke(f, lib::forward(arg), lib::forward(args)...))
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
template
inline constexpr auto invoke(F&& f, Args&&... args)
MPARK_RETURN(lib::forward(f)(lib::forward(args)...))
#ifdef _MSC_VER
#pragma warning(pop)
#endif
} // namespace detail_
template
inline constexpr auto invoke(F&& f, Args&&... args) MPARK_RETURN(
detail_::invoke(lib::forward(f), lib::forward(args)...))
namespace detail_ {
template
struct invoke_result {};
template
struct invoke_result<
void_t(), std::declval()...))>,
F,
Args...>
: identity(), std::declval()...))> {};
} // namespace detail_
template
using invoke_result = detail_::invoke_result;
template
using invoke_result_t = typename invoke_result::type;
namespace detail_ {
template
struct is_invocable : std::false_type {};
template
struct is_invocable>, F, Args...>
: std::true_type {};
template
struct is_invocable_r : std::false_type {};
template
struct is_invocable_r>, R, F, Args...>
: std::is_convertible, R> {};
} // namespace detail_
template