|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2005-07-14 20:24:53
Cory Nelson <phrosty_at_[hidden]> writes:
> I have a function like:
>
> template<typename CharT>
> void foo() {
> std::basic_string<CharT> str;
>
> ...
>
> if(str=="bar")
>
> ...
> }
>
> I'd like to check at compile time if CharT is a char or wchar_t to
> specialize the string used to compare- MPL seems like the thing I
> would use for this but documentation on doing this seems scarce.
Probably because MPL is a slightly overpowerful tool for the job.
> Could someone give me an example?
template <class CharT>
charT const* bar() { return "bar"; }
template <>
wchar_t const* bar() { return L"bar"; }
...
if (str==bar<CharT>())
...
HTH,
-- Dave Abrahams Boost Consulting www.boost-consulting.com
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