Boost logo

Boost Users :

Subject: Re: [Boost-users] OT: generic template type from specific type?
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-02-21 08:00:55


2009/2/19 Neal Becker <ndbecker2_at_[hidden]>

> Say I have:
>
> template<typename in_t>
> void F (in_t & in) ...
>
> main() {
> F<std::vector<int> > (...)
>
> Suppose in_t is a templated container, such as std::vector<int>. Is there
> a
> way within the function 'F' to get the generic container type,
> 'std::vector'
> when F is instantiated with a specific e.g., std::vector<int>?
>

Maybe this will help you.

template <class Base, class Arg> struct rebind; template <template <class>
class Base, class T, class Arg> struct rebind<Base<T>, Arg> { typedef
Base<Arg> type; }; template <class In> void foo() { // d is of type
container<double>. typename rebind<In, double>::type d; } template <class T>
struct container {}; int main() { foo<container<int> >(); }

With vector and other STL containers it's a bit
harder, because they can have more than one
template parameter.

Roman Perepelitsa.



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