From 2959b2348fe969458cff8add0ed85eff4c93df97 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 22 Aug 2015 17:18:24 +0200 Subject: Improve "callable" detection in serializer stream interface This version "sees" operator() in the base. --- xml/serializer | 13 ++++--------- xml/serializer.ixx | 11 ++++++----- 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'xml') diff --git a/xml/serializer b/xml/serializer index ee5779b..6251392 100644 --- a/xml/serializer +++ b/xml/serializer @@ -292,16 +292,11 @@ namespace xml std::size_t depth_; }; - // Stream-like interface for serializer. If the passed argument - // is a function with the void f(serializer&) signature or is a - // function object with the void operator() (serializer&) const - // operator, then this function (object) is called with the passed - // serializer. Otherwise, the argument is passed to the serializer's - // characters() function. + // Stream-like interface for serializer. If the passed argument is + // callable with the serializer as its argument, then this function + // (object) is called with the passed serializer. Otherwise, the + // argument is passed to the serializer's characters() function. // - serializer& - operator<< (serializer&, void (*func) (serializer&)); - template serializer& operator<< (serializer&, const T& value); diff --git a/xml/serializer.ixx b/xml/serializer.ixx index 465fede..59d329f 100644 --- a/xml/serializer.ixx +++ b/xml/serializer.ixx @@ -155,26 +155,27 @@ namespace xml namespace details { - // Detect whether T defines void operator(A) const. + // Detect whether T is callable with argument A. // template - struct is_functor + struct is_callable { typedef char no[1]; typedef char yes[2]; + template static X declval (); - template struct check; + template struct check; template static no& test (...); template - static yes& test (check*); + static yes& test (check () (declval ()), 0)>*); static const bool value = sizeof (test (0)) == sizeof (yes); }; - template ::value> + template ::value> struct inserter; template -- cgit v1.1