/usr/include/xtensor/xutils.hpp is in xtensor-dev 0.10.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 | /***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XUTILS_HPP
#define XUTILS_HPP
#include <algorithm>
#include <array>
#include <complex>
#include <cstddef>
#include <initializer_list>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "xtensor_config.hpp"
namespace xt
{
/****************
* declarations *
****************/
template <class T>
struct remove_class;
template <class F, class... T>
void for_each(F&& f, std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()));
template <class F, class R, class... T>
R accumulate(F&& f, R init, const std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()));
template <class... T>
struct or_;
template <class... T>
struct and_;
template <bool... B>
struct or_c;
template <bool... B>
struct and_c;
template <std::size_t I, class... Args>
constexpr decltype(auto) argument(Args&&... args) noexcept;
template <class R, class F, class... S>
R apply(std::size_t index, F&& func, const std::tuple<S...>& s) noexcept(noexcept(std::declval<F>()));
template <class T, class S>
void nested_copy(T&& iter, const S& s);
template <class T, class S>
void nested_copy(T&& iter, std::initializer_list<S> s);
template <class U>
struct initializer_dimension;
template <class R, class T>
constexpr R shape(T t);
template <class T, class S>
constexpr bool check_shape(T t, S first, S last);
template <class C>
bool resize_container(C& c, typename C::size_type size);
template <class T, std::size_t N>
bool resize_container(std::array<T, N>& a, typename std::array<T, N>::size_type size);
template <class S>
S make_sequence(typename S::size_type size, typename S::value_type v);
template <class R, class A>
decltype(auto) forward_sequence(A&& s);
// equivalent to std::size(c) in c++17
template <class C>
constexpr auto sequence_size(const C& c) -> decltype(c.size());
// equivalent to std::size(a) in c++17
template <class T, std::size_t N>
constexpr std::size_t sequence_size(const T (&a)[N]);
/*******************************
* remove_class implementation *
*******************************/
template <class T>
struct remove_class
{
};
template <class C, class R, class... Args>
struct remove_class<R (C::*)(Args...)>
{
typedef R type(Args...);
};
template <class C, class R, class... Args>
struct remove_class<R (C::*)(Args...) const>
{
typedef R type(Args...);
};
template <class T>
using remove_class_t = typename remove_class<T>::type;
/***************************
* for_each implementation *
***************************/
namespace detail
{
template <std::size_t I, class F, class... T>
inline typename std::enable_if<I == sizeof...(T), void>::type
for_each_impl(F&& /*f*/, std::tuple<T...>& /*t*/) noexcept(noexcept(std::declval<F>()))
{
}
template <std::size_t I, class F, class... T>
inline typename std::enable_if<I < sizeof...(T), void>::type
for_each_impl(F&& f, std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()))
{
f(std::get<I>(t));
for_each_impl<I + 1, F, T...>(std::forward<F>(f), t);
}
}
template <class F, class... T>
inline void for_each(F&& f, std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()))
{
detail::for_each_impl<0, F, T...>(std::forward<F>(f), t);
}
/*****************************
* accumulate implementation *
*****************************/
namespace detail
{
template <std::size_t I, class F, class R, class... T>
inline std::enable_if_t<I == sizeof...(T), R>
accumulate_impl(F&& /*f*/, R init, const std::tuple<T...>& /*t*/) noexcept(noexcept(std::declval<F>()))
{
return init;
}
template <std::size_t I, class F, class R, class... T>
inline std::enable_if_t<I < sizeof...(T), R>
accumulate_impl(F&& f, R init, const std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()))
{
R res = f(init, std::get<I>(t));
return accumulate_impl<I + 1, F, R, T...>(std::forward<F>(f), res, t);
}
}
template <class F, class R, class... T>
inline R accumulate(F&& f, R init, const std::tuple<T...>& t) noexcept(noexcept(std::declval<F>()))
{
return detail::accumulate_impl<0, F, R, T...>(f, init, t);
}
/**********************
* or_ implementation *
**********************/
template <>
struct or_<> : std::integral_constant<bool, false>
{
};
template <class T, class... Ts>
struct or_<T, Ts...>
: std::integral_constant<bool, T::value || or_<Ts...>::value>
{
};
/***********************
* and_ implementation *
***********************/
template <>
struct and_<> : std::integral_constant<bool, true>
{
};
template <class T, class... Ts>
struct and_<T, Ts...>
: std::integral_constant<bool, T::value && and_<Ts...>::value>
{
};
/**********************************
* or_c and and_c implementations *
**********************************/
template <bool... B>
struct or_c : or_<std::integral_constant<bool, B>...>
{
};
template <bool... B>
struct and_c : and_<std::integral_constant<bool, B>...>
{
};
/***************************
* argument implementation *
***************************/
namespace detail
{
template <std::size_t I>
struct getter
{
template <class Arg, class... Args>
static constexpr decltype(auto) get(Arg&& /*arg*/, Args&&... args) noexcept
{
return getter<I - 1>::get(std::forward<Args>(args)...);
}
};
template <>
struct getter<0>
{
template <class Arg, class... Args>
static constexpr Arg&& get(Arg&& arg, Args&&... /*args*/) noexcept
{
return std::forward<Arg>(arg);
}
};
}
template <std::size_t I, class... Args>
constexpr decltype(auto) argument(Args&&... args) noexcept
{
static_assert(I < sizeof...(Args), "I should be lesser than sizeof...(Args)");
return detail::getter<I>::get(std::forward<Args>(args)...);
}
/************************
* apply implementation *
************************/
namespace detail
{
template <class R, class F, std::size_t I, class... S>
R apply_one(F&& func, const std::tuple<S...>& s) noexcept(noexcept(std::declval<F>()))
{
return func(std::get<I>(s));
}
template <class R, class F, std::size_t... I, class... S>
R apply(std::size_t index, F&& func, std::index_sequence<I...> /*seq*/, const std::tuple<S...>& s) noexcept(noexcept(std::declval<F>()))
{
using FT = std::add_pointer_t<R(F&&, const std::tuple<S...>&)>;
static const std::array<FT, sizeof...(I)> ar = {{&apply_one<R, F, I, S...>...}};
return ar[index](std::forward<F>(func), s);
}
}
template <class R, class F, class... S>
inline R apply(std::size_t index, F&& func, const std::tuple<S...>& s) noexcept(noexcept(std::declval<F>()))
{
return detail::apply<R>(index, std::forward<F>(func), std::make_index_sequence<sizeof...(S)>(), s);
}
/***************************
* nested_initializer_list *
***************************/
template <class T, std::size_t I>
struct nested_initializer_list
{
using type = std::initializer_list<typename nested_initializer_list<T, I - 1>::type>;
};
template <class T>
struct nested_initializer_list<T, 0>
{
using type = T;
};
template <class T, std::size_t I>
using nested_initializer_list_t = typename nested_initializer_list<T, I>::type;
/******************************
* nested_copy implementation *
******************************/
template <class T, class S>
inline void nested_copy(T&& iter, const S& s)
{
*iter++ = s;
}
template <class T, class S>
inline void nested_copy(T&& iter, std::initializer_list<S> s)
{
for (auto it = s.begin(); it != s.end(); ++it)
{
nested_copy(std::forward<T>(iter), *it);
}
}
/****************************************
* initializer_dimension implementation *
****************************************/
namespace detail
{
template <class U>
struct initializer_depth_impl
{
static constexpr std::size_t value = 0;
};
template <class T>
struct initializer_depth_impl<std::initializer_list<T>>
{
static constexpr std::size_t value = 1 + initializer_depth_impl<T>::value;
};
}
template <class U>
struct initializer_dimension
{
static constexpr std::size_t value = detail::initializer_depth_impl<U>::value;
};
/************************************
* initializer_shape implementation *
************************************/
namespace detail
{
template <std::size_t I>
struct initializer_shape_impl
{
template <class T>
static constexpr std::size_t value(T t)
{
return t.size() == 0 ? 0 : initializer_shape_impl<I - 1>::value(*t.begin());
}
};
template <>
struct initializer_shape_impl<0>
{
template <class T>
static constexpr std::size_t value(T t)
{
return t.size();
}
};
template <class R, class U, std::size_t... I>
constexpr R initializer_shape(U t, std::index_sequence<I...>)
{
using size_type = typename R::value_type;
return {size_type(initializer_shape_impl<I>::value(t))...};
}
}
template <class R, class T>
constexpr R shape(T t)
{
return detail::initializer_shape<R, decltype(t)>(t, std::make_index_sequence<initializer_dimension<decltype(t)>::value>());
}
/******************************
* check_shape implementation *
******************************/
namespace detail
{
template <class T, class S>
struct predshape
{
constexpr predshape(S first, S last)
: m_first(first), m_last(last)
{
}
constexpr bool operator()(const T&) const
{
return m_first == m_last;
}
S m_first;
S m_last;
};
template <class T, class S>
struct predshape<std::initializer_list<T>, S>
{
constexpr predshape(S first, S last)
: m_first(first), m_last(last)
{
}
constexpr bool operator()(std::initializer_list<T> t) const
{
return *m_first == t.size() && std::all_of(t.begin(), t.end(), predshape<T, S>(m_first + 1, m_last));
}
S m_first;
S m_last;
};
}
template <class T, class S>
constexpr bool check_shape(T t, S first, S last)
{
return detail::predshape<decltype(t), S>(first, last)(t);
}
/***********************************
* resize_container implementation *
***********************************/
template <class C>
inline bool resize_container(C& c, typename C::size_type size)
{
c.resize(size);
return true;
}
template <class T, std::size_t N>
inline bool resize_container(std::array<T, N>& /*a*/, typename std::array<T, N>::size_type size)
{
return size == N;
}
/********************************
* make_sequence implementation *
********************************/
namespace detail
{
template <class S>
struct sequence_builder
{
using value_type = typename S::value_type;
using size_type = typename S::size_type;
inline static S make(size_type size, value_type v)
{
return S(size, v);
}
};
template <class T, std::size_t N>
struct sequence_builder<std::array<T, N>>
{
using sequence_type = std::array<T, N>;
using value_type = typename sequence_type::value_type;
using size_type = typename sequence_type::size_type;
inline static sequence_type make(size_type /*size*/, value_type v)
{
sequence_type s;
s.fill(v);
return s;
}
};
}
template <class S>
inline S make_sequence(typename S::size_type size, typename S::value_type v)
{
return detail::sequence_builder<S>::make(size, v);
}
/***********************************
* forward_sequence implementation *
***********************************/
namespace detail
{
template <class R, class A, class E = void>
struct sequence_forwarder
{
template <class T>
static inline R forward(const T& r)
{
return R(std::begin(r), std::end(r));
}
};
template <class I, std::size_t L, class A>
struct sequence_forwarder<std::array<I, L>, A,
std::enable_if_t<!std::is_same<std::array<I, L>, A>::value>>
{
using R = std::array<I, L>;
template <class T>
static inline R forward(const T& r)
{
R ret;
std::copy(std::begin(r), std::end(r), std::begin(ret));
return ret;
}
};
template <class R>
struct sequence_forwarder<R, R>
{
template <class T>
static inline T&& forward(typename std::remove_reference<T>::type& t) noexcept
{
return static_cast<T&&>(t);
}
template <class T>
static inline T&& forward(typename std::remove_reference<T>::type&& t) noexcept
{
return static_cast<T&&>(t);
}
};
}
template <class R, class A>
inline decltype(auto) forward_sequence(A&& s)
{
using forwarder = detail::sequence_forwarder<
std::decay_t<R>,
std::remove_cv_t<std::remove_reference_t<A>>
>;
return forwarder::template forward<A>(s);
}
/*************************************
* promote_shape and promote_strides *
*************************************/
namespace detail
{
template <class T1, class T2>
constexpr std::common_type_t<T1, T2> imax(const T1& a, const T2& b)
{
return a > b ? a : b;
}
// Variadic meta-function returning the maximal size of std::arrays.
template <class... T>
struct max_array_size;
template <>
struct max_array_size<>
{
static constexpr std::size_t value = 0;
};
template <class T, class... Ts>
struct max_array_size<T, Ts...> : std::integral_constant<std::size_t, imax(std::tuple_size<T>::value, max_array_size<Ts...>::value)>
{
};
// Simple is_array and only_array meta-functions
template <class S>
struct is_array
{
static constexpr bool value = false;
};
template <class T, std::size_t N>
struct is_array<std::array<T, N>>
{
static constexpr bool value = true;
};
template <class... S>
using only_array = and_<is_array<S>...>;
// The promote_index meta-function returns std::vector<promoted_value_type> in the
// general case and an array of the promoted value type and maximal size if all
// arguments are of type std::array
template <bool A, class... S>
struct promote_index_impl;
template <class... S>
struct promote_index_impl<false, S...>
{
using type = std::vector<typename std::common_type<typename S::value_type...>::type>;
};
template <class... S>
struct promote_index_impl<true, S...>
{
using type = std::array<typename std::common_type<typename S::value_type...>::type, max_array_size<S...>::value>;
};
template <>
struct promote_index_impl<true>
{
using type = std::array<std::size_t, 0>;
};
template <class... S>
struct promote_index
{
using type = typename promote_index_impl<only_array<S...>::value, S...>::type;
};
}
template <class... S>
using promote_shape_t = typename detail::promote_index<S...>::type;
template <class... S>
using promote_strides_t = typename detail::promote_index<S...>::type;
/**************************
* closure implementation *
**************************/
template <class S>
struct closure
{
using underlying_type = std::conditional_t<std::is_const<std::remove_reference_t<S>>::value,
const std::decay_t<S>,
std::decay_t<S>>;
using type = typename std::conditional<std::is_lvalue_reference<S>::value,
underlying_type&,
underlying_type>::type;
};
template <class S>
using closure_t = typename closure<S>::type;
template <class S>
struct const_closure
{
using underlying_type = const std::decay_t<S>;
using type = typename std::conditional<std::is_lvalue_reference<S>::value,
underlying_type&,
underlying_type>::type;
};
template <class S>
using const_closure_t = typename const_closure<S>::type;
/******************************
* ptr_closure implementation *
******************************/
template <class S>
struct ptr_closure
{
using underlying_type = std::conditional_t<std::is_const<std::remove_reference_t<S>>::value,
const std::decay_t<S>,
std::decay_t<S>>;
using type = std::conditional_t<std::is_lvalue_reference<S>::value,
underlying_type*,
underlying_type>;
};
template <class S>
using ptr_closure_t = typename ptr_closure<S>::type;
template <class S>
struct const_ptr_closure
{
using underlying_type = const std::decay_t<S>;
using type = std::conditional_t<std::is_lvalue_reference<S>::value,
underlying_type*,
underlying_type>;
};
template <class S>
using const_ptr_closure_t = typename const_ptr_closure<S>::type;
/***************************
* apply_cv implementation *
***************************/
namespace detail
{
template <class T, class U, bool = std::is_const<std::remove_reference_t<T>>::value,
bool = std::is_volatile<std::remove_reference_t<T>>::value>
struct apply_cv_impl
{
using type = U;
};
template <class T, class U>
struct apply_cv_impl<T, U, true, false>
{
using type = const U;
};
template <class T, class U>
struct apply_cv_impl<T, U, false, true>
{
using type = volatile U;
};
template <class T, class U>
struct apply_cv_impl<T, U, true, true>
{
using type = const volatile U;
};
template <class T, class U>
struct apply_cv_impl<T&, U, false, false>
{
using type = U&;
};
template <class T, class U>
struct apply_cv_impl<T&, U, true, false>
{
using type = const U&;
};
template <class T, class U>
struct apply_cv_impl<T&, U, false, true>
{
using type = volatile U&;
};
template <class T, class U>
struct apply_cv_impl<T&, U, true, true>
{
using type = const volatile U&;
};
}
template <class T, class U>
struct apply_cv
{
using type = typename detail::apply_cv_impl<T, U>::type;
};
template <class T, class U>
using apply_cv_t = typename apply_cv<T, U>::type;
/*****************************
* is_complex implementation *
*****************************/
namespace detail
{
template <typename T>
struct is_complex : public std::false_type
{
};
template <typename T>
struct is_complex<std::complex<T>> : public std::true_type
{
};
}
template <class T>
struct is_complex
{
static constexpr bool value = detail::is_complex<std::decay_t<T>>::value;
};
/*************************************
* complex_value_type implementation *
*************************************/
template <typename T>
struct complex_value_type
{
using type = T;
};
template <typename T>
struct complex_value_type<std::complex<T>>
{
using type = T;
};
template <class T>
using complex_value_type_t = typename complex_value_type<T>::type;
/*********************************
* forward_offset implementation *
*********************************/
namespace detail
{
template <class T, class M>
struct forward_type
{
using type = apply_cv_t<T, M>&&;
};
template <class T, class M>
struct forward_type<T&, M>
{
using type = apply_cv_t<T, M>&;
};
template <class T, class M>
using forward_type_t = typename forward_type<T, M>::type;
}
template <class M, std::size_t I, class T>
constexpr detail::forward_type_t<T, M> forward_offset(T&& v) noexcept
{
using forward_type = detail::forward_type_t<T, M>;
using cv_value_type = std::remove_reference_t<forward_type>;
using byte_type = apply_cv_t<std::remove_reference_t<T>, char>;
return static_cast<forward_type>(
*reinterpret_cast<cv_value_type*>(
reinterpret_cast<byte_type*>(&v) + I
)
);
}
/**********************************************
* forward_real & forward_imag implementation *
**********************************************/
// forward_real
template <class T>
auto forward_real(T&& v)
-> std::enable_if_t<!is_complex<T>::value, detail::forward_type_t<T, T>> // real case -> forward
{
return static_cast<detail::forward_type_t<T, T>>(v);
}
template <class T>
auto forward_real(T&& v)
-> std::enable_if_t<is_complex<T>::value, detail::forward_type_t<T, typename std::decay_t<T>::value_type>> // complex case -> forward the real part
{
return forward_offset<typename std::decay_t<T>::value_type, 0>(v);
}
// forward_imag
template <class T>
auto forward_imag(T &&)
-> std::enable_if_t<!is_complex<T>::value, std::decay_t<T>> // real case -> always return 0 by value
{
return 0;
}
template <class T>
auto forward_imag(T&& v)
-> std::enable_if_t<is_complex<T>::value, detail::forward_type_t<T, typename std::decay_t<T>::value_type>> // complex case -> forwards the imaginary part
{
using real_type = typename std::decay_t<T>::value_type;
return forward_offset<real_type, sizeof(real_type)>(v);
}
/**************************
* to_array implementation *
***************************/
namespace detail
{
template <class T, std::size_t N, std::size_t... I>
constexpr std::array<std::remove_cv_t<T>, N> to_array_impl(T (&a)[N], std::index_sequence<I...>)
{
return {{a[I]...}};
}
}
template <class T, std::size_t N>
constexpr std::array<std::remove_cv_t<T>, N> to_array(T (&a)[N])
{
return detail::to_array_impl(a, std::make_index_sequence<N>{});
}
/********************************
* sequence_size implementation *
********************************/
// equivalent to std::size(c) in c++17
template <class C>
constexpr auto sequence_size(const C& c) -> decltype(c.size())
{
return c.size();
}
// equivalent to std::size(a) in c++17
template <class T, std::size_t N>
constexpr std::size_t sequence_size(const T (&)[N])
{
return N;
}
/*****************************************
* has_raw_data_interface implementation *
*****************************************/
template <typename T>
class has_raw_data_interface
{
template <typename C>
static std::true_type test(decltype(std::declval<C>().raw_data_offset()));
template <typename C>
static std::false_type test(...);
public:
constexpr static bool value = decltype(test<T>(std::size_t(0)))::value == true;
};
/******************************
* is_complete implementation *
******************************/
namespace detail
{
template <typename T>
struct is_complete_impl
{
template <typename U>
static auto test(U*) -> std::integral_constant<bool, sizeof(U) == sizeof(U)>;
static auto test(...) -> std::false_type;
using type = decltype(test((T*)0));
};
}
template <typename T>
struct is_complete : detail::is_complete_impl<T>::type {};
/*********************************************
* xtrivial_default_construct implementation *
*********************************************/
#if defined(__clang__)
#if !(defined(__APPLE__))
// CLANG && LINUX
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
}
namespace std { template <class T> struct is_trivially_default_constructible; }
namespace std { template <class T> struct has_trivial_default_constructor; }
namespace xt
{
namespace detail
{
template <bool C, class T>
struct xtrivial_default_construct_impl;
template <class T>
struct xtrivial_default_construct_impl<true, T> : std::is_trivially_default_constructible<T> {};
template <class T>
struct xtrivial_default_construct_impl<false, T> : std::has_trivial_default_constructor<T> {};
}
template <class T>
using xtrivially_default_constructible = detail::xtrivial_default_construct_impl<is_complete<std::is_trivially_default_constructible<double>>::value, T>;
#pragma clang diagnostic pop
#else
// CLANG && APPLE
template <class T>
using xtrivially_default_constructible = std::is_trivially_default_constructible<T>;
#endif
#else
// NOT CLANG
#if defined(__GNUC__) && (__GNUC__ < 5 || (__GNUC__ == 5 && __GNUC_MINOR__ < 1))
// OLD GCC
template <class T>
using xtrivially_default_constructible = std::has_trivial_default_constructor<T>;
#else
template <class T>
using xtrivially_default_constructible = std::is_trivially_default_constructible<T>;
#endif
#endif
}
#endif
|