Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first cut requiring c++17 #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
.vscode/
.cache/

# codespaces clean
.venv/

# build directories
build/
build-*/
/build/
/build-*/
/*-build/
cmake-build-*/
docker-*-build/
/Debug/
Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ project (camp
LANGUAGES CXX C
VERSION 0.1.0)

# Default to C++11 if not set so GTest/GMock can build
# Default to C++17 if not set so GTest/GMock can build
if (NOT BLT_CXX_STD)
set(BLT_CXX_STD "c++14" CACHE STRING "")
set(BLT_CXX_STD "c++17" CACHE STRING "")
else()
set(_unsupported_cxx "c++98" "c++11")
set(_unsupported_cxx "c++98" "c++11" "c++14")
if (BLT_CXX_STD IN_LIST _unsupported_cxx)
message(FATAL_ERROR "CAMP and the RAJA framework no longer support c++11, select a c++ standard of 14 or higher")
message(FATAL_ERROR "CAMP and the RAJA framework no longer support c++ standards below c++17, select a c++ standard of 17 or higher")
endif()
endif()

include(cmake/load_blt.cmake)


cmake_dependent_option(CAMP_ENABLE_TESTS "Build tests" On "ENABLE_TESTS" Off)

# if ENABLE_TESTS is defined by a parent project, and
Expand Down Expand Up @@ -112,7 +111,7 @@ target_include_directories (camp INTERFACE
)
set_target_properties (camp PROPERTIES
INTERFACE_LIB_VERSION $camp_VERSION
INTERFACE_COMPILE_FEATURES cxx_std_14)
INTERFACE_COMPILE_FEATURES cxx_std_17)

include(CMakePackageConfigHelpers)

Expand Down
25 changes: 14 additions & 11 deletions include/camp/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ namespace internal
{
}

CAMP_HOST_DEVICE constexpr const Type& get_inner() const noexcept
CAMP_HOST_DEVICE constexpr auto& get_inner(::camp::num<index>) const noexcept
{
return val;
}

CAMP_HOST_DEVICE constexpr Type& get_inner() noexcept { return val; }
CAMP_HOST_DEVICE constexpr auto& get_inner(::camp::num<index>) noexcept
{
return val;
}

public:
Type val;
Expand All @@ -130,12 +133,12 @@ namespace internal
{
}

CAMP_HOST_DEVICE constexpr const Type& get_inner() const noexcept
CAMP_HOST_DEVICE constexpr const Type& get_inner(::camp::num<index>) const noexcept
{
return ((Type const*)this)[0];
}

CAMP_HOST_DEVICE constexpr Type& get_inner() noexcept
CAMP_HOST_DEVICE constexpr Type& get_inner(::camp::num<index>) noexcept
{
return ((Type*)this)[0];
}
Expand All @@ -151,15 +154,15 @@ CAMP_HOST_DEVICE constexpr auto& get(const Tuple& t) noexcept
{
using internal::tpl_get_store;
static_assert(tuple_size<Tuple>::value > index, "index out of range");
return static_cast<tpl_get_store<Tuple, index> const&>(t.base).get_inner();
return t.base.get_inner(num<index>{});
}

template <camp::idx_t index, class Tuple>
CAMP_HOST_DEVICE constexpr auto& get(Tuple& t) noexcept
{
using internal::tpl_get_store;
static_assert(tuple_size<Tuple>::value > index, "index out of range");
return static_cast<tpl_get_store<Tuple, index>&>(t.base).get_inner();
return t.base.get_inner(num<index>{});
}

// by type
Expand All @@ -171,8 +174,7 @@ CAMP_HOST_DEVICE constexpr auto& get(const Tuple& t) noexcept
static_assert(!std::is_same<camp::nil, index_type>::value,
"invalid type index");

return static_cast<tpl_get_store<Tuple, index_type::value>&>(t.base)
.get_inner();
return t.base.get_inner(index_type{});
}

template <typename T, class Tuple>
Expand All @@ -183,8 +185,7 @@ CAMP_HOST_DEVICE constexpr auto& get(Tuple& t) noexcept
static_assert(!std::is_same<camp::nil, index_type>::value,
"invalid type index");

return static_cast<tpl_get_store<Tuple, index_type::value>&>(t.base)
.get_inner();
return t.base.get_inner(index_type{});
}

namespace internal
Expand Down Expand Up @@ -228,10 +229,12 @@ namespace internal
template <typename RTuple>
CAMP_HOST_DEVICE tuple_helper& operator=(const RTuple& rhs)
{
return (camp::sink((this->tuple_storage<Indices, Types>::get_inner() =
return (camp::sink((this->get_inner(num<Indices>{}) =
::camp::get<Indices>(rhs))...),
*this);
}

using internal::tuple_storage<Indices, Types>::get_inner...;
};

template <typename Types, typename Indices>
Expand Down