Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
maybe_static_value.h172 linesDownload Raw Back to __mdspan
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___MDSPAN_MAYBE_STATIC_VALUE_HPP45#define _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP46 47#ifndef __cuda_std__48#include <__config>49#endif // __cuda_std__50 51#include "../__mdspan/dynamic_extent.h"52#include "../__mdspan/macros.h"53#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS54#include "../__mdspan/no_unique_address.h"55#endif56 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// This is only needed for the non-standard-layout version of partially66// static array.67// Needs to be after the includes above to work with the single header generator68#if !__MDSPAN_PRESERVE_STANDARD_LAYOUT69 70_LIBCUDACXX_BEGIN_NAMESPACE_STD71 72#if _LIBCUDACXX_STD_VER > 1173 74//==============================================================================75 76namespace __detail {77 78// static case79template <class _dynamic_t, class _static_t, _static_t __v,80          _static_t __is_dynamic_sentinal = dynamic_extent,81          size_t __array_entry_index = 0>82struct __maybe_static_value {83  static constexpr _static_t __static_value = __v;84  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept {85    return static_cast<_dynamic_t>(__v);86  }87  template <class _Up>88  __MDSPAN_FORCE_INLINE_FUNCTION constexpr89  __mdspan_enable_fold_comma90  __set_value(_Up&& /*__rhs*/) noexcept {91    // Should we assert that the value matches the static value here?92    return {};93  }94 95  //--------------------------------------------------------------------------96 97  __MDSPAN_INLINE_FUNCTION_DEFAULTED98  constexpr __maybe_static_value() noexcept = default;99  __MDSPAN_INLINE_FUNCTION_DEFAULTED100  constexpr __maybe_static_value(__maybe_static_value const&) noexcept = default;101  __MDSPAN_INLINE_FUNCTION_DEFAULTED102  constexpr __maybe_static_value(__maybe_static_value&&) noexcept = default;103  __MDSPAN_INLINE_FUNCTION_DEFAULTED104  __MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value const&) noexcept = default;105  __MDSPAN_INLINE_FUNCTION_DEFAULTED106  __MDSPAN_CONSTEXPR_14_DEFAULTED __maybe_static_value& operator=(__maybe_static_value&&) noexcept = default;107  __MDSPAN_INLINE_FUNCTION_DEFAULTED108  ~__maybe_static_value() noexcept = default;109 110  __MDSPAN_INLINE_FUNCTION111  constexpr explicit __maybe_static_value(_dynamic_t const&) noexcept {112    // Should we assert that the value matches the static value here?113  }114 115  //--------------------------------------------------------------------------116 117};118 119// dynamic case120template <class _dynamic_t, class _static_t, _static_t __is_dynamic_sentinal, size_t __array_entry_index>121struct __maybe_static_value<_dynamic_t, _static_t, __is_dynamic_sentinal, __is_dynamic_sentinal,122                            __array_entry_index>123#ifdef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS124    : __no_unique_address_emulation<_Tp>125#endif126{127  static constexpr _static_t __static_value = __is_dynamic_sentinal;128#ifndef _LIBCUDACXX_HAS_NO_ATTRIBUTE_NO_UNIQUE_ADDRESS129  _LIBCUDACXX_NO_UNIQUE_ADDRESS _dynamic_t __v = {};130  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept {131    return __v;132  }133  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept {134    return __v;135  }136  template <class _Up>137  __MDSPAN_FORCE_INLINE_FUNCTION constexpr138  __mdspan_enable_fold_comma139  __set_value(_Up&& __rhs) noexcept {140    __v = (_Up &&)rhs;141    return {};142  }143#else144  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t __value() const noexcept {145    return this->__no_unique_address_emulation<_dynamic_t>::__ref();146  }147  __MDSPAN_FORCE_INLINE_FUNCTION constexpr _dynamic_t &__ref() noexcept {148    return this->__no_unique_address_emulation<_dynamic_t>::__ref();149  }150  template <class _Up>151  __MDSPAN_FORCE_INLINE_FUNCTION constexpr152  __mdspan_enable_fold_comma153  __set_value(_Up&& __rhs) noexcept {154    this->__no_unique_address_emulation<_dynamic_t>::__ref() = (_Up &&)__rhs;155    return {};156  }157#endif158};159 160} // namespace __detail161 162//==============================================================================163 164 165#endif // _LIBCUDACXX_STD_VER > 11166 167_LIBCUDACXX_END_NAMESPACE_STD168 169#endif // !__MDSPAN_PRESERVE_STANDARD_LAYOUT170 171#endif // _LIBCUDACXX___MDSPAN_MAYBE_STATIC_VALUE_HPP172 
codekingpro/portable-devtools · Team Ai