Skip to content

Commit

Permalink
Merge branch 'mabe-systematics' into sum-distance-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
emilydolson authored Feb 29, 2024
2 parents f11a154 + 0fc3e62 commit c416384
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
74 changes: 37 additions & 37 deletions include/emp/base/_optional_throw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,43 @@

namespace emp {

/// Base case for assert_print...
inline void assert_print_opt(std::stringstream &) { ; }

/// Print out information about the next variable and recurse...
template <typename T, typename... EXTRA>
void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T, typename... EXTRA>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;}

template <typename T, typename... EXTRA>
void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_second_opt(ss, std::forward<EXTRA>(extra)...);
}

void assert_print_first_opt(std::stringstream & ss, int placeholder) {;}

template <typename... EXTRA>
void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) {
std::stringstream ss;
ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n";
assert_print_first_opt(ss, std::forward<EXTRA>(extra)...);
throw(std::runtime_error(ss.str()));
}
/// Base case for assert_print...
inline void assert_print_opt(std::stringstream &) { ; }

/// Print out information about the next variable and recurse...
template <typename T, typename... EXTRA>
void assert_print_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T, typename... EXTRA>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
assert_print_opt(ss, std::forward<EXTRA>(extra)...);
}

template <typename T>
void assert_print_second_opt(std::stringstream & ss, std::string name, T && val) {;}

template <typename T, typename... EXTRA>
void assert_print_first_opt(std::stringstream & ss, std::string name, T && val, EXTRA &&... extra) {
if constexpr ( emp::is_streamable<std::stringstream, T>::value ) {
ss << name << ": [" << val << "]" << std::endl;
} else ss << name << ": (non-streamable type)" << std::endl;
assert_print_second_opt(ss, std::forward<EXTRA>(extra)...);
}

void assert_print_first_opt(std::stringstream & ss, int placeholder) {;}

template <typename... EXTRA>
void assert_throw_opt(std::string filename, size_t line, std::string expr, std::string message, EXTRA &&... extra) {
std::stringstream ss;
ss << "Internal Error (in " << filename << " line " << line << "): " << expr << ".\n\n Message: " << message << "\n\n";
assert_print_first_opt(ss, std::forward<EXTRA>(extra)...);
throw(std::runtime_error(ss.str()));
}
}

#endif // #ifndef EMP_BASE__OPTIONAL_THROW_HPP_INCLUDE
2 changes: 1 addition & 1 deletion tests/base/optional_throw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
/**
* @file
* @brief TODO.
#include <iostream>
*/

#include "third-party/Catch/single_include/catch2/catch.hpp"

#undef NDEBUG
#define TDEBUG 1
#include "emp/base/optional_throw.hpp"

Expand Down

0 comments on commit c416384

Please sign in to comment.