Allocator rebind problems

I'm trying to rebind allocator to some other type but it doesn't want to work no matter what I do

f I try this
1
2
3
4
5
6
7
#include <memory>

int main()
{
  std::allocator<int> A;
  typedef A::rebind<double>::other double_Allocator;
}

Here I'm getting this error
error: 'A' does not name a type


If I try this
1
2
3
4
5
6
7
8
9
#include <memory>

template<typename alloc, typename T>
using Rebind =typename alloc::rebind<T>::other;

int main()
{
    Rebind<std::allocator<int>, double> double_Allocator;
}

I'm getting this error
4:37: error: expected ';' before '<' token
4:37: error: expected unqualified-id before '<' token
In substitution of 'template<class alloc, class T> using Rebind = typename alloc::rebind [with alloc = std::allocator<int>; T = double]':
8:39: required from here
4:37: error: 'typename std::allocator<int>::rebind' names 'template<class _Tp1> struct std::allocator<int>::rebind', which is not a type
In function 'int main()':
8:57: error: invalid type in declaration before ';' token


What am I doing wrong?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
#include <memory>

int main()
{
    // std::allocator<int> A;
    // typedef A::rebind<double>::other double_Allocator;
    typedef std::allocator<int>::rebind<double>::other double_Allocator;

    using A = std::allocator<int> ;
    typedef A::rebind<double>::other double_Allocator;
}


1
2
3
4
5
6
7
8
9
10
11
#include <memory>

template<typename alloc, typename T>
using Rebind = typename alloc::template rebind<T>::other;
// see: 'The template disambiguator for dependent names' 
// http://en.cppreference.com/w/cpp/language/dependent_name

int main()
{
    Rebind<std::allocator<int>, double> double_Allocator;
}
Ohh, thank you man very much :) Much appreciated!
Topic archived. No new replies allowed.