ไม่มีการแปลงจาก std::allocator เป็น const allocator_type

ฉันกำลังพยายามใช้ตัวจัดสรรที่สอดคล้องเพื่อใช้กับ MKL ใน C ++ 11 ฉันมี:

template <typename T, size_t TALIGN = 16, size_t TBLOCK = 4>
class aligned_allocator : public std::allocator<T>
{
    typedef typename std::allocator<T>::pointer pointer;
    typedef typename std::allocator<T>::size_type size_type;
public:
    pointer allocate(size_type n, const void *hint = nullptr);
    void deallocate(pointer p, size_type n);
};

ที่อื่นฉันมี:

template<typename T> using aligned_vector = std::vector<T, aligned_allocator<T>>;

และสุดท้าย ฉันมีโอเปอเรเตอร์โอเวอร์โหลดนี้:

inline aligned_vector<double> operator+(aligned_vector<double> x, aligned_vector<double> y)
{
    aligned_vector<double> z(x.size());
    vdAdd(x.size(), x.data(), y.data(), z.data());
    return z;
}

ทั้งหมดนี้คอมไพล์และทำงานได้อย่างสมบูรณ์แบบภายใต้ทั้ง icc และ clang แต่ด้วย GCC 4.9 มันจะไม่คอมไพล์เว้นแต่ฉันจะสร้าง x และ y ทั้งสอง const-references เหตุใด GCC จึงต้องการสิ่งนี้ ในเมื่อที่อื่นไม่ต้องการ


person Alex Reinking    schedule 11.08.2014    source แหล่งที่มา
comment
rebindของคุณอยู่ที่ไหน?   -  person Cubbi    schedule 12.08.2014
comment
@Cubbi: rebind ไม่จำเป็นใน C ++ 11   -  person Kerrek SB    schedule 12.08.2014


คำตอบ (1)


คุณหายไป rebind:

template <typename U> struct rebind { typedef aligned_allocator<U> other; };

ที่กล่าวว่าคุณไม่ควรสืบทอดจาก std::allocator: ทำไมไม่สืบทอดจาก std::allocator

person ecatmur    schedule 11.08.2014
comment
ว้าว นั่นมันรวดเร็วมาก - และวิธีแก้ปัญหา! ขอบคุณ! - person Alex Reinking; 12.08.2014
comment
แต่ทำไมมันถึงใช้งานได้กับเสียงดังกราวและ icc แต่ไม่ใช่ gcc? (นี่คือคำถามของฉัน) - person Alex Reinking; 12.08.2014
comment
@AlexReinking clang 3.4.1 และ icc 13.0.1 ทั้งคู่ต้องการ rebind สำหรับฉัน: goo.gl/Cgu1oF - person ecatmur; 12.08.2014
comment
อ่า ดูเหมือนว่า icc 14.0.3 จะไม่เหมาะกับฉัน - person Alex Reinking; 12.08.2014
comment
@AlexReinking: libstdc++ ของ GCC นั้นยังห่างไกลจากการปฏิบัติตาม C ++ 11 คอนเทนเนอร์ส่วนใหญ่ไม่ได้ใช้คอนเทนเนอร์ในแง่ของข้อกำหนดการจัดสรรของ C ++ 11 - person Kerrek SB; 12.08.2014