From 351b71b452e663a695fabd3be35ca63dfcbe3b4f Mon Sep 17 00:00:00 2001 From: Daniel Garcia-Sanchez Date: Tue, 30 Oct 2018 08:36:45 +0100 Subject: [PATCH] Use overload instead of enable_if --- source/base/hdf5.cc | 104 +++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 68 deletions(-) diff --git a/source/base/hdf5.cc b/source/base/hdf5.cc index 60287de5e1..8e8db82d8f 100644 --- a/source/base/hdf5.cc +++ b/source/base/hdf5.cc @@ -116,35 +116,27 @@ namespace HDF5 // // Instead of using functions with std::enable_if, "constexpr if" from C++17 // could be used - template - typename std::enable_if< - std::is_same>::value, - std::vector>::type - get_container_dimensions(const Container &data) + template + std::vector + get_container_dimensions(const std::vector &data) { return std::vector{data.size()}; } - template - typename std::enable_if< - std::is_same>::value, - std::vector>::type - get_container_dimensions(const Container &data) + template + std::vector + get_container_dimensions(const Vector &data) { return std::vector{data.size()}; } - template - typename std::enable_if< - std::is_same>::value, - std::vector>::type - get_container_dimensions(const Container &data) + template + std::vector + get_container_dimensions(const FullMatrix &data) { return std::vector{data.m(), data.n()}; } @@ -155,35 +147,27 @@ namespace HDF5 // For a std::vector the function returns int(vector_size) // For a Vector the function returns int(vector_size) // For a FullMatrix the function returns int(rows*columns) - template - typename std::enable_if< - std::is_same>::value, - unsigned int>::type - get_container_size(const Container &data) + template + unsigned int + get_container_size(const std::vector &data) { return static_cast(data.size()); } - template - typename std::enable_if< - std::is_same>::value, - unsigned int>::type - get_container_size(const Container &data) + template + unsigned int + get_container_size(const Vector &data) { return static_cast(data.size()); } - template - typename std::enable_if< - std::is_same>::value, - unsigned int>::type - get_container_size(const Container &data) + template + unsigned int + get_container_size(const FullMatrix &data) { return static_cast(data.m() * data.n()); } @@ -191,12 +175,9 @@ namespace HDF5 // This function returns the pointer to the raw data of a container - template - typename std::enable_if< - std::is_same>::value, - void *>::type - get_container_pointer(Container &data) + template + void * + get_container_pointer(std::vector &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong @@ -205,11 +186,9 @@ namespace HDF5 - template - typename std::enable_if< - std::is_same>::value, - void *>::type - get_container_pointer(Container &data) + template + void * + get_container_pointer(Vector &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong. @@ -219,12 +198,9 @@ namespace HDF5 - template - typename std::enable_if< - std::is_same>::value, - void *>::type - get_container_pointer(Container &data) + template + void * + get_container_pointer(FullMatrix &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong. @@ -237,12 +213,9 @@ namespace HDF5 // This function returns the pointer to the raw data of a container // The returned pointer is const, which means that it can be used only to // read the data - template - typename std::enable_if< - std::is_same>::value, - const void *>::type - get_container_const_pointer(const Container &data) + template + const void * + get_container_const_pointer(const std::vector &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong @@ -251,11 +224,9 @@ namespace HDF5 - template - typename std::enable_if< - std::is_same>::value, - const void *>::type - get_container_const_pointer(const Container &data) + template + const void * + get_container_const_pointer(const Vector &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong. @@ -265,12 +236,9 @@ namespace HDF5 - template - typename std::enable_if< - std::is_same>::value, - const void *>::type - get_container_const_pointer(const Container &data) + template + const void * + get_container_const_pointer(const FullMatrix &data) { // It is very important to pass the variable "data" by reference otherwise // the pointer will be wrong. -- 2.39.5