Skip to content

Remove SFINAE in some places #3

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

Merged
merged 3 commits into from
Jan 24, 2022
Merged
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
36 changes: 10 additions & 26 deletions include/openPMD/DatatypeHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,27 @@ struct HasErrorMessageMember<
* @tparam n As in switchType().
* @tparam ReturnType As in switchType().
* @tparam Action As in switchType().
* @tparam Placeholder For SFINAE, set to void.
* @tparam Args As in switchType().
*/
template<
int n,
typename ReturnType,
typename Action,
typename Placeholder,
typename... Args >
struct CallUndefinedDatatype
{
static ReturnType call( Args &&... )
{
static_assert(
HasErrorMessageMember< Action >::value,
"[switchType] Action needs either an errorMsg member of type "
"std::string or operator()<unsigned>() overloads." );
throw std::runtime_error(
"[" + std::string( Action::errorMsg ) + "] Unknown Datatype." );
}
};

template< int n, typename ReturnType, typename Action, typename... Args >
struct CallUndefinedDatatype<
n,
ReturnType,
Action,
// Enable this, if no error message member is found.
// action.template operator()<n>() will be called instead
typename std::enable_if< !HasErrorMessageMember< Action >::value >::type,
Args... >
{
static ReturnType call( Args &&... args )
{
return Action::template call< n >( std::forward< Args >( args )... );
if constexpr( HasErrorMessageMember< Action >::value )
{
throw std::runtime_error(
"[" + std::string( Action::errorMsg ) + "] Unknown Datatype." );
}
else
{
return Action::template call< n >( std::forward< Args >( args )... );
}
throw std::runtime_error( "Unreachable!" );
}
};
}
Expand Down Expand Up @@ -235,7 +221,6 @@ auto switchType( Datatype dt, Args &&... args )
0,
ReturnType,
Action,
void,
Args &&... >::call( std::forward< Args >( args )... );
default:
throw std::runtime_error(
Expand Down Expand Up @@ -323,7 +308,6 @@ auto switchNonVectorType( Datatype dt, Args &&... args )
0,
ReturnType,
Action,
void,
Args &&... >::call( std::forward< Args >( args )... );
default:
throw std::runtime_error(
Expand Down
2 changes: 0 additions & 2 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ auto switchAdios2AttributeType( Datatype dt, Args &&... args )
0,
ReturnType,
Action,
void,
Args &&... >::call( std::forward< Args >( args )... );
default:
throw std::runtime_error(
Expand Down Expand Up @@ -284,7 +283,6 @@ auto switchAdios2VariableType( Datatype dt, Args &&... args )
0,
ReturnType,
Action,
void,
Args &&... >::
call( std::forward< Args >( args )... );
default:
Expand Down
161 changes: 56 additions & 105 deletions include/openPMD/IO/ADIOS/ADIOS2IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,37 @@ namespace detail
{
// Helper structs for calls to the switchType function

template< typename > struct IsVector
{
static constexpr bool value = false;
};

template< typename T > struct IsVector< std::vector< T > >
{
static constexpr bool value = true;
};

template< typename T >
inline constexpr bool IsVector_v = IsVector< T >::value;

template< typename > struct IsArray
{
static constexpr bool value = false;
};

template< typename T, size_t n > struct IsArray< std::array< T, n > >
{
static constexpr bool value = true;
};

template< typename T >
inline constexpr bool IsArray_v = IsArray< T >::value;

template< typename T >
inline constexpr bool IsUnsupportedComplex_v =
std::is_same_v< T, std::complex< long double > > ||
std::is_same_v< T, std::vector< std::complex< long double > > >;

struct DatasetReader
{
template< typename T >
Expand Down Expand Up @@ -582,18 +613,6 @@ namespace detail
template< typename T >
struct AttributeTypes
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
T value );

static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );

static void
createAttribute(
adios2::IO & IO,
Expand Down Expand Up @@ -630,26 +649,6 @@ namespace detail

template< > struct AttributeTypes< std::complex< long double > >
{
static void
oldCreateAttribute(
adios2::IO &,
std::string,
std::complex< long double > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}

static void
oldReadAttribute(
adios2::IO &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}

static void
createAttribute(
adios2::IO &,
Expand Down Expand Up @@ -682,26 +681,6 @@ namespace detail

template< > struct AttributeTypes< std::vector< std::complex< long double > > >
{
static void
oldCreateAttribute(
adios2::IO &,
std::string,
const std::vector< std::complex< long double > > & )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}

static void
oldReadAttribute(
adios2::IO &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}

static void
createAttribute(
adios2::IO &,
Expand Down Expand Up @@ -736,18 +715,6 @@ namespace detail

template < typename T > struct AttributeTypes< std::vector< T > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::vector< T > & value );

static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );

static void
createAttribute(
adios2::IO & IO,
Expand Down Expand Up @@ -791,18 +758,6 @@ namespace detail
template<>
struct AttributeTypes< std::vector< std::string > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::vector< std::string > & value );

static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );

static void
createAttribute(
adios2::IO & IO,
Expand Down Expand Up @@ -846,18 +801,6 @@ namespace detail
template < typename T, size_t n >
struct AttributeTypes< std::array< T, n > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::array< T, n > & value );

static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );

static void
createAttribute(
adios2::IO & IO,
Expand Down Expand Up @@ -898,18 +841,36 @@ namespace detail
}
};

namespace bool_repr
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for now a duplication of the same code inside AttributeTypes< bool >. The latter will be removed as soon as the new ADIOS2 schema is fully removed.

{
using rep = detail::bool_representation;

static constexpr rep toRep( bool b )
{
return b ? 1U : 0U;
}


static constexpr bool fromRep( rep r )
{
return r != 0;
}
}

template <> struct AttributeTypes< bool >
{
using rep = detail::bool_representation;

static void
oldCreateAttribute( adios2::IO & IO, std::string name, bool value );
static constexpr rep toRep( bool b )
{
return b ? 1U : 0U;
}

static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );

static constexpr bool fromRep( rep r )
{
return r != 0;
}

static void
createAttribute(
Expand All @@ -925,16 +886,6 @@ namespace detail
std::shared_ptr< Attribute::resource > resource );


static constexpr rep toRep( bool b )
{
return b ? 1U : 0U;
}


static constexpr bool fromRep( rep r )
{
return r != 0;
}

static bool
attributeUnchanged( adios2::IO & IO, std::string name, bool val )
Expand Down
Loading