Skip to content

Commit

Permalink
explicitly pass return type to template
Browse files Browse the repository at this point in the history
  • Loading branch information
JDanielSmith committed Dec 23, 2022
1 parent 4937ccd commit e219282
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modules/c++/hdf5.lite/include/hdf5/lite/Info.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ struct FileInfo final
};


CODA_OSS_API FileInfo fileInfo(const coda_oss::filesystem::path&);
CODA_OSS_API FileInfo fileInfo(coda_oss::filesystem::path);

}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/c++/hdf5.lite/source/Info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static hdf5::lite::FileInfo fileInfo_(const coda_oss::filesystem::path& fileName
return hdf5::lite::FileInfo{};
}

hdf5::lite::FileInfo hdf5::lite::fileInfo(const coda_oss::filesystem::path& fileName)
hdf5::lite::FileInfo hdf5::lite::fileInfo(coda_oss::filesystem::path fileName)
{
return details::try_catch_H5Exceptions(fileInfo_, fileName);
return details::try_catch_H5Exceptions<hdf5::lite::FileInfo>(fileInfo_, fileName);
}
5 changes: 1 addition & 4 deletions modules/c++/hdf5.lite/source/Read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,5 @@ static types::RowCol<size_t> readFile_(const coda_oss::filesystem::path& fileNam
types::RowCol<size_t> hdf5::lite::readFile(coda_oss::filesystem::path fileName, std::string datasetName,
std::vector<double>& result)
{
types::RowCol<size_t> retval;
auto call_readFile_ = [&](void*) { retval = readFile_(fileName, datasetName, result); };
details::try_catch_H5Exceptions(call_readFile_);
return retval;
return details::try_catch_H5Exceptions<types::RowCol<size_t>>(readFile_, fileName, datasetName, result);
}
10 changes: 5 additions & 5 deletions modules/c++/hdf5.lite/source/hdf5.lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ namespace details
// Call the given function, converting H5 exceptions to our own.
void try_catch_H5Exceptions_(std::function<void(void*)> f, void* context = nullptr);

template<typename TFunc, typename ...TArgs>
template<typename TReturn, typename TFunc, typename ...TArgs>
auto try_catch_H5Exceptions(TFunc f, TArgs&&... args)
{
// Figure out return type by "calling" the function at compile-time
decltype(f(std::forward<TArgs...>(args...))) retval;

//decltype(f(std::forward<TArgs>(args)...)) retval;
TReturn retval;

// "Hide" the arguments inside of a lambda
auto call_f = [&](void*) { retval = f(std::forward<TArgs...>(args...)); };
auto call_f = [&](void*) { retval = f(std::forward<TArgs>(args)...); };
details::try_catch_H5Exceptions_(call_f);
return retval;
}


}
}
}

0 comments on commit e219282

Please sign in to comment.