記録更新

C++0x では新しく allocator_traits というのが入るわけですが、このシグネチャはこうなってます。

namespace std {
  template <class Alloc> struct allocator_traits {
    typedef Alloc allocator_type;

    typedef typename Alloc::value_type value_type;

    typedef see below pointer;
    typedef see below const_pointer;
    typedef see below void_pointer;
    typedef see below const_void_pointer;

    typedef see below difference_type;
    typedef see below size_type;

    typedef see below propagate_on_container_copy_assignment;
    typedef see below propagate_on_container_move_assignment;
    typedef see below propagate_on_container_swap;

    template <class T> using rebind_alloc = see below;
    template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >;

    static pointer allocate(Alloc& a, size_type n);
    static pointer allocate(Alloc& a, size_type n, const_void_pointer hint);

    static void deallocate(Alloc& a, pointer p, size_type n);

    template <class T, class... Args>
    static void construct(Alloc& a, T* p, Args&&... args);

    template <class T>
    static void destroy(Alloc& a, T* p);

    static size_type max_size(const Alloc& a);

    static Alloc select_on_container_copy_construction(const Alloc& rhs);
  };
}
N3035 §20.9.4

注目すべきは select_on_container_copy_construction です。
今までさんざん長いとされていた set_symmetric_difference の 24 文字を 13 文字も上回る 37 文字!
このメンバ関数は static なのでクラス名付きでアクセスするわけですから、実際に呼び出すときには

allocator_traits<Alloc>::select_on_container_copy_construction(rhs);

とかなってかなりいい感じに。


しかも型名も含めるなら propagate_on_container_copy_assignment と propagate_on_container_move_assignment が 38 文字!
Alloc がテンプレート引数になってる場合は typename が必要になるので、

typename allocator_traits<Alloc>::propagate_on_container_copy_assignment;
typename allocator_traits<Alloc>::propagate_on_container_move_assignment;

となって、更にいい感じに。


C++0x になって「set_symmetric_difference って名前長すぎだよね」とか言ってたらどこぞやの闇の軍団に鼻で笑われることになるので気をつけましょう!