Programmer
Programmer

Reputation: 8697

BOOST - Class template queue

I was trying to read on Boost Class template queue and found the below content of class template:

template<typename T, typename A0, typename A1, typename A2> 
class queue {
    public:
  // member classes/structs/unions
  template<typename T, typename... Options> 
  struct implementation_defined {
    // types
    typedef node_allocator allocator;
    typedef std::size_t    size_type;
  };
  // construct/copy/destruct
  queue(void);
  template<typename U> 
    explicit queue(typename node_allocator::template rebind< U >::other const &);
  explicit queue(allocator const &);
  explicit queue(size_type);
  template<typename U> 
    queue(size_type, 
          typename node_allocator::template rebind< U >::other const &);
  ~queue(void);
.......
};

I was trying to understand the template step by step - so

template<typename T, typename A0, typename A1, typename A2> 

meant to me that the template would be created when provided types T, A0, A1 and A2 like

queue<int, char, myclass, char>

where myclass is a user defined class - I hope I am correct in my understanding. But what I could not understand is the below section -

  template<typename T, typename... Options> 
  struct implementation_defined {
    // types
    typedef node_allocator allocator;
    typedef std::size_t    size_type;
  };
  // construct/copy/destruct
  queue(void);
  template<typename U> 
    explicit queue(typename node_allocator::template rebind< U >::other const &);

It seems a template inside another template - but then how do we provide types to instantiate

template<typename T, typename... Options>

and

template<typename U>

Is there a way to understand template construction like classes to understand what a templates methods are its arguments and return type?

Upvotes: 0

Views: 94

Answers (1)

user7860670
user7860670

Reputation: 37488

template<typename U> is a queue constructor function template. Its parameter is deduced from argument you are passing when invoking it.

struct implementation_defined is a regular nested class, that is not actually a template itself. It looks like a documentation issue because it is actually defined as

struct implementation_defined
{
    typedef node_allocator allocator;
    typedef std::size_t size_type;
};

Upvotes: 1

Related Questions