Skip to content

Commit

Permalink
Allow printing more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Oct 24, 2017
1 parent 32b98e5 commit ac5fd4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions jngen.h
Original file line number Diff line number Diff line change
Expand Up @@ -2571,6 +2571,7 @@ using jngen::setMod;
#include <iostream>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>

Expand All @@ -2593,7 +2594,7 @@ class Has ## name ## Helper<T,\
> : public std::true_type {};\

#define JNGEN_HAS_FUNCTION(name)\
detail::Has ## name ## Helper<T>::value
::jngen::detail::Has ## name ## Helper<T>::value

JNGEN_DEFINE_FUNCTION_CHECKER(
OstreamMethod,
Expand Down Expand Up @@ -2653,11 +2654,17 @@ printValue(out, value, OutputModifier{}, PTagMax{})

JNGEN_DECLARE_PRINTER(!JNGEN_HAS_OSTREAM(), 0)
{
// can't just write 'false' here because assertion always fails
static_assert(!std::is_same<T, T>::value, "operator<< is undefined");
(void)out;
static bool locked = false;

ensure(
!locked,
std::string{} + "You are trying to print a type for which "
"operator<< is not defined: " + typeid(T).name());

locked = true;
(void)mod;
(void)t;
out << t;
locked = false;
}

JNGEN_DECLARE_PRINTER(JNGEN_HAS_OSTREAM(), 10)
Expand Down
17 changes: 12 additions & 5 deletions printers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <utility>
#include <vector>

Expand All @@ -27,7 +28,7 @@ class Has ## name ## Helper<T,\
> : public std::true_type {};\

#define JNGEN_HAS_FUNCTION(name)\
detail::Has ## name ## Helper<T>::value
::jngen::detail::Has ## name ## Helper<T>::value

JNGEN_DEFINE_FUNCTION_CHECKER(
OstreamMethod,
Expand Down Expand Up @@ -87,11 +88,17 @@ printValue(out, value, OutputModifier{}, PTagMax{})

JNGEN_DECLARE_PRINTER(!JNGEN_HAS_OSTREAM(), 0)
{
// can't just write 'false' here because assertion always fails
static_assert(!std::is_same<T, T>::value, "operator<< is undefined");
(void)out;
static bool locked = false;

ensure(
!locked,
std::string{} + "You are trying to print a type for which "
"operator<< is not defined: " + typeid(T).name());

locked = true;
(void)mod;
(void)t;
out << t;
locked = false;
}

JNGEN_DECLARE_PRINTER(JNGEN_HAS_OSTREAM(), 10)
Expand Down

0 comments on commit ac5fd4e

Please sign in to comment.