|
Boost Users : |
Subject: Re: [Boost-users] [lexical_cast] How is the degenerate case handled?
From: jbosboom_at_[hidden]
Date: 2009-04-20 14:39:47
> I recall that function templates cannot be partially specialised, so
> we (or the user in question) would have to do complete specialisation
> instead, so the given type would have to be known.
Okay, so function templates can't be partially specialized like that, but
class templates can, and classes can have static member functions. So how
about
template<class Target, class Source>
Target lexical_cast(const Source& arg) {
return lexical_cast_impl<Target, Source>::cast(arg);
}
template<class Target, class Source>
class lexical_cast_impl {
inline static cast(const Source& arg) { /* ... */ }
};
//partial specialization for Target = Source
template<class Target>
class lexical_cast_impl<Target, Target> {
inline static cast(const Source& arg) {return arg;}
};
--Jeffrey Bosboom
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net