
On Thu, Feb 26, 2009 at 8:18 AM, Andrey Semashev <andrey.semashev@gmail.com> wrote:
Emil Dotchevski wrote:
Anyway, another question: is there a way to make operator() not be a template? It should be doable if you only need to receive the "source" argument to convert from. But if you want other arguments as well, I can't figure out how to do it without a template, unless to resort to type erasure.
Well, one way to take arguments is to tell the compiler that your function or operator() takes arguments, right? std::string operator()( uuid const & value, int arg1, float arg2 ); C++ was type-safe even before templates were introduced. :)
If you're trying to extract the conversion code into a separate TU, then you can leave the operator() a template, so it is able to transform the named arguments pack into a call of a non-template function with positional arguments only.
I'm not trying to extract the conversion code into a separate TU, I'm trying to justify putting it in the header. :) If I'm the maintainer of class uuid and I am asked to provide a to-string conversion, you'll find it very difficult to convince me that it makes sense to replace this: #include <string> namespace user { class uuid; std::string to_string( uuid const & ); } with all of this: #include <boost/mpl/and.hpp> #include <boost/mpl/bool.hpp> #include <boost/typeof/typeof.hpp> #include <boost/utility/enable_if.hpp> #include <boost/type_traits/is_integral.hpp> #include <boost/parameter/keyword.hpp> #include <kitchen_sink.hpp> namespace user { struct uuid { unsigned char value_[16]; }; struct uuid_to_string_tag {}; template< typename ToT > typename boost::enable_if< boost::conversion::is_string< ToT >, uuid_to_string_tag
::type get_conversion_tag(uuid*, ToT*);
} // namespace user namespace boost { namespace conversion { template< typename ToT > struct converter_impl< ToT, user::uuid_to_string_tag > { typedef ToT result_type; template< typename ArgsT > ToT operator() (ArgsT const& args) const { .... } }; } // namespace conversion } // namespace boost Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode