codekingpro/portable-devtools
114k
1/*2//@HEADER3// ************************************************************************4//5// Kokkos v. 2.06// Copyright (2019) Sandia Corporation7//8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,9// the U.S. Government retains certain rights in this software.10//11// Redistribution and use in source and binary forms, with or without12// modification, are permitted provided that the following conditions are13// met:14//15// 1. Redistributions of source code must retain the above copyright16// notice, this list of conditions and the following disclaimer.17//18// 2. Redistributions in binary form must reproduce the above copyright19// notice, this list of conditions and the following disclaimer in the20// documentation and/or other materials provided with the distribution.21//22// 3. Neither the name of the Corporation nor the names of the23// contributors may be used to endorse or promote products derived from24// this software without specific prior written permission.25//26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.37//38// Questions? Contact Christian R. Trott (crtrott@sandia.gov)39//40// ************************************************************************41//@HEADER42*/43 44#ifndef _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP45#define _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP46 47#ifndef __cuda_std__48#include <__config>49#endif // __cuda_std__50 51#include "../__mdspan/macros.h"52#include "../__type_traits/enable_if.h"53#include "../__type_traits/is_empty.h"54#include "../__type_traits/is_trivially_destructible.h"55#include "../__utility/move.h"56 57#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)58# pragma GCC system_header59#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)60# pragma clang system_header61#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)62# pragma system_header63#endif // no system header64 65_LIBCUDACXX_BEGIN_NAMESPACE_STD66 67#if _LIBCUDACXX_STD_VER > 1168 69namespace __detail {70 71//==============================================================================72 73template <class _Tp, size_t _Disambiguator = 0, class _Enable = void>74struct __no_unique_address_emulation {75 using __stored_type = _Tp;76 _Tp __v;77 __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept {78 return __v;79 }80 __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept {81 return __v;82 }83};84 85// Empty case86// This doesn't work if _Tp is final, of course, but we're not using anything87// like that currently. That kind of thing could be added pretty easily though88template <class _Tp, size_t _Disambiguator>89struct __no_unique_address_emulation<90 _Tp, _Disambiguator,91 _CUDA_VSTD::enable_if_t<_LIBCUDACXX_TRAIT(_CUDA_VSTD::is_empty, _Tp) &&92 // If the type isn't trivially destructible, its destructor93 // won't be called at the right time, so don't use this94 // specialization95 _LIBCUDACXX_TRAIT(_CUDA_VSTD::is_trivially_destructible, _Tp)>> :96#ifdef __MDSPAN_COMPILER_MSVC97 // MSVC doesn't allow you to access public static member functions of a type98 // when you *happen* to privately inherit from that type.99 protected100#else101 // But we still want this to be private if possible so that we don't accidentally102 // access members of _Tp directly rather than calling __ref() first, which wouldn't103 // work if _Tp happens to be stateful and thus we're using the unspecialized definition104 // of __no_unique_address_emulation above.105 private106#endif107 _Tp {108 using __stored_type = _Tp;109 __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp const &__ref() const noexcept {110 return *static_cast<_Tp const *>(this);111 }112 __MDSPAN_FORCE_INLINE_FUNCTION constexpr _Tp &__ref() noexcept {113 return *static_cast<_Tp *>(this);114 }115 116 __MDSPAN_INLINE_FUNCTION_DEFAULTED117 constexpr __no_unique_address_emulation() noexcept = default;118 __MDSPAN_INLINE_FUNCTION_DEFAULTED119 constexpr __no_unique_address_emulation(120 __no_unique_address_emulation const &) noexcept = default;121 __MDSPAN_INLINE_FUNCTION_DEFAULTED122 constexpr __no_unique_address_emulation(123 __no_unique_address_emulation &&) noexcept = default;124 __MDSPAN_INLINE_FUNCTION_DEFAULTED125 __MDSPAN_CONSTEXPR_14_DEFAULTED __no_unique_address_emulation &126 operator=(__no_unique_address_emulation const &) noexcept = default;127 __MDSPAN_INLINE_FUNCTION_DEFAULTED128 __MDSPAN_CONSTEXPR_14_DEFAULTED __no_unique_address_emulation &129 operator=(__no_unique_address_emulation &&) noexcept = default;130 __MDSPAN_INLINE_FUNCTION_DEFAULTED131 ~__no_unique_address_emulation() noexcept = default;132 133 // Explicitly make this not a reference so that the copy or move134 // constructor still gets called.135 __MDSPAN_INLINE_FUNCTION136 explicit constexpr __no_unique_address_emulation(_Tp const& __v) noexcept : _Tp(__v) {}137 __MDSPAN_INLINE_FUNCTION138 explicit constexpr __no_unique_address_emulation(_Tp&& __v) noexcept : _Tp(_CUDA_VSTD::move(__v)) {}139};140 141//==============================================================================142 143} // end namespace __detail144 145#endif // _LIBCUDACXX_STD_VER > 11146 147_LIBCUDACXX_END_NAMESPACE_STD148 149#endif // _LIBCUDACXX__LIBCUDACXX_NO_UNIQUE_ADDRESS_HPP150 