Skip to content
Snippets Groups Projects
Commit d953de45 authored by Tobias Malkmus's avatar Tobias Malkmus
Browse files

[optinal] use std::optional on newer compilers

parent ffd4ea39
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,9 @@
# :code:`DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION`
# True if C++17's class template argument deduction is supported
#
# :code:`DUNE_HAVE_CXX_OPTIONAL`
# True if C++17's optional implementation is supported
#
# .. cmake_variable:: DISABLE_CXX_VERSION_CHECK
#
# You may set this variable to TRUE to disable checking for
......@@ -350,6 +353,21 @@ check_cxx_source_compiles("
" DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
)
# support for C++17's optional implementation
check_cxx_source_compiles("
#include <optional>
#include <string>
int main()
{
std::optional< std::string > a;
std::string b = a.value_or( \"empty\" );
}
" DUNE_HAVE_CXX_OPTIONAL
)
# find the threading library
# Use a copy FindThreads from CMake 3.1 due to its support of pthread
if(NOT DEFINED THREADS_PREFER_PTHREAD_FLAG)
......
......@@ -29,6 +29,9 @@
/* does the compiler support C++17's class template argument deduction? */
#cmakedefine DUNE_HAVE_CXX_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
/* does the compiler support C++17's optional? */
#cmakedefine DUNE_HAVE_CXX_OPTIONAL 1
/* does the compiler support conditionally throwing exceptions in constexpr context? */
#cmakedefine DUNE_SUPPORTS_CXX_THROW_IN_CONSTEXPR 1
......
......@@ -7,12 +7,24 @@
#include <type_traits>
#include <utility>
#ifdef DUNE_HAVE_CXX_OPTIONAL
#include <optional>
#endif // #ifdef DUNE_HAVE_CXX_OPTIONAL
namespace Dune
{
namespace Std
{
#ifdef DUNE_HAVE_CXX_OPTIONAL
// In case of C++ standard >= 17 we forward optionals into our namespace
template< class T >
using optional = std::optional< T >;
#else
// In case of C++ standard < 17 we take the fallback implementation
// nullopt
// -------
......@@ -414,11 +426,14 @@ namespace Dune
return optional< typename std::decay< T >::type >( std::forward< T >( value ) );
}
#endif //#ifdef DUNE_HAVE_CXX_OPTIONAL
} // namespace Std
} // namespace Dune
#ifndef DUNE_HAVE_CXX_OPTIONAL
namespace std
{
......@@ -447,4 +462,6 @@ namespace std
} // namespace std
#endif //#ifndef DUNE_HAVE_CXX_OPTIONAL
#endif // #ifndef DUNE_COMMON_STD_OPTIONAL_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment