包装用于DLL导出的标准库模板(需要进行健全性检查)

时间:2017-09-26 18:02:31

标签: c++ c++11 templates vector dllexport

我认为我对从DLL(或lib)的std库中导出模板(向量,字符串,映射等等)的问题(不同的实现,编译的二进制差异等)有很好的把握。 )。但是我发现我也不喜欢使用自定义矢量/列表/地图类,并发现在类中创建一个接口来导出它们的功能,这是一个繁琐的重复,所以我得出结论,我只是想尝试换行尽我所能地说对象(并接受任何性能影响)。这就是说我想知道你们是否能够理智地检查我到目前为止做了什么。

所以这就是我走下去的道路(先用矢量测试)。我创建了一个类似于std :: vector的类,只是命名为vector。目的是将其包含在命名空间内的另一个文件中,以便新的向量不会与其他任何内容冲突。我目前正在开发一个openCl库,这就是代码的来源。

opencl_std.h

#ifndef _opencl_util_opencl_std_h
#define _opencl_util_opencl_std_h

#include "opencl_util_export.h"

#include <string>
#include <vector>

#ifdef opencl_util_EXPORTS
#define OPENCL_UTIL_EXTERN
#else
#define OPENCL_UTIL_EXTERN extern
#endif

namespace cl{namespace util
{

#include "std_wrappers\vector.h"

OPENCL_UTIL_EXTERN template class OPENCL_UTIL_EXPORT ::cl::util::vector<::size_t>;

}}//namespace cl::util

#endif //_opencl_util_opencl_std_h

opencl.cpp

#include "opencl_std.h"

namespace cl{namespace util
{

#include "std_wrappers\vector.cpp"

}}//namespace cl::util

OPENCL_UTIL_EXPORT是必需的dllimport / dllexport,OPENCL_UTIL_EXTERN在导入时将类设置为extern。 std_wrappers \ vector.h包含类的声明,std_wrappers \ vector.cpp包含定义。尽管该类是一个模板,但拆分声明/定义的工作原理是该类通过此调用显式实例化(以及导出)。

OPENCL_UTIL_EXTERN template class OPENCL_UTIL_EXPORT ::cl::util::vector<::size_t>;

std_wrappers \ vector.h

template<class _Myvec, class _IterTy>
class vector_iterator;

template<class _Myvec, class _IterTy>
class vector_const_iterator
{
public:
    typedef vector_const_iterator<_Myvec, _IterTy> _Myiter;

    typedef typename _Myvec::value_type value_type;
    typedef typename _Myvec::difference_type difference_type;
    typedef typename _Myvec::const_pointer pointer;
    typedef typename _Myvec::const_reference reference;

    vector_const_iterator(const typename _IterTy &iter);
    vector_const_iterator(const _Myiter &right);
    vector_const_iterator(_Myiter &&right);

//    vector_const_iterator(typename _IterTy &&iter);
    ~vector_const_iterator();

    _Myiter &operator=(const _Myiter &right);
    _Myiter &operator=(_Myiter &&right);

    reference operator*() const;
    pointer operator->() const;
    _Myiter &operator++();
    _Myiter operator++(int);
    _Myiter &operator--();
    _Myiter operator--(int);
    _Myiter &operator+=(difference_type offset);
    _Myiter operator+(difference_type offset) const;
    _Myiter &operator-=(difference_type offset);
    _Myiter operator-(difference_type offset) const;
    difference_type operator-(const _Myiter &right) const;
    reference operator[](difference_type offset) const;
    bool operator==(const _Myiter &right) const;
    bool operator!=(const _Myiter &right) const;
    bool operator<(const _Myiter &right) const;
    bool operator>(const _Myiter &right) const;
    bool operator<=(const _Myiter &right) const;
    bool operator>=(const _Myiter &right) const;

    friend vector_iterator<_Myvec, _IterTy>;

private:
    typename _IterTy *_iter;
};


template<class _Myvec, class _IterTy>
class vector_iterator:public vector_const_iterator<_Myvec, _IterTy>
{
public:
    typedef vector_iterator<_Myvec, _IterTy> _Myiter;
    typedef vector_const_iterator<_Myvec, _IterTy> _Mybase;

    typedef typename _Myvec::value_type value_type;
    typedef typename _Myvec::difference_type difference_type;
    typedef typename _Myvec::pointer pointer;
    typedef typename _Myvec::reference reference;

    vector_iterator(const typename _IterTy &iter);
    vector_iterator(const _Myiter &right);
    vector_iterator(_Myiter &&right);
//    vector_iterator(typename _IterTy &&iter);

    _Myiter &operator=(const _Myiter &right);
    _Myiter &operator=(_Myiter &&right);

    reference operator*() const;
    pointer operator->() const;
    _Myiter &operator++();
    _Myiter operator++(int);
    _Myiter &operator--();
    _Myiter operator--(int);
    _Myiter &operator+=(difference_type offset);
    _Myiter operator+(difference_type offset) const;
    _Myiter &operator-=(difference_type offset);
    _Myiter operator-(difference_type offset) const;
    difference_type operator-(const _Mybase &right) const;
    reference operator[](difference_type offset) const;
};

template<class _Ty, class _Alloc=std::allocator<_Ty> >
class vector
{
public:
    typedef vector<_Ty, _Alloc> _Myt;
    typedef std::vector<_Ty, _Alloc> _StdTy;

    typedef typename std::vector<_Ty, _Alloc>::value_type value_type;
    typedef typename std::vector<_Ty, _Alloc>::allocator_type allocator_type;
    typedef typename std::vector<_Ty, _Alloc>::size_type size_type;
    typedef typename std::vector<_Ty, _Alloc>::difference_type difference_type;

    typedef typename std::vector<_Ty, _Alloc>::reference reference;
    typedef typename std::vector<_Ty, _Alloc>::const_reference const_reference;
    typedef typename std::vector<_Ty, _Alloc>::pointer pointer;
    typedef typename std::vector<_Ty, _Alloc>::const_pointer const_pointer;

    typedef vector_iterator<_StdTy, typename _StdTy::iterator> iterator;
    typedef vector_const_iterator<_StdTy, typename _StdTy::const_iterator> const_iterator;
    typedef vector_iterator<_StdTy, typename _StdTy::reverse_iterator> reverse_iterator;
    typedef vector_const_iterator<_StdTy, typename _StdTy::const_reverse_iterator> const_reverse_iterator;
//    typedef typename std::vector<_Ty, _Alloc>::iterator iterator;
//    typedef typename std::vector<_Ty, _Alloc>::const_iterator const_iterator;
//    typedef typename std::vector<_Ty, _Alloc>::reverse_iterator reverse_iterator;
//    typedef typename std::vector<_Ty, _Alloc>::const_reverse_iterator const_reverse_iterator;

public:
    vector() noexcept;
    explicit vector(const _Alloc &alloc) noexcept;
    explicit vector(size_type count);
    vector(size_type count, const value_type &value);
    vector(size_type count, const value_type &value, const _Alloc &alloc=std::allocator<_Ty>);
#ifdef STD_WRAPPER_EXPORT
    template<class InputIt> vector(InputIt first, InputIt last, const _Alloc &alloc=std::allocator<_Ty>)
    { _vector=new std::vector<_Ty, _Alloc>(first, last, alloc); }
#endif//STD_WRAPPER_EXPORT
    vector(const _Myt &right);
    vector(const _Myt &right, const _Alloc &alloc);
    vector(_Myt &&right) noexcept;
    vector(_Myt &&right, const _Alloc &alloc);
#ifdef STD_WRAPPER_EXPORT
    vector(const _StdTy &right);
    vector(const _StdTy &right, const _Alloc &alloc);
    vector(_StdTy &&right) noexcept;
    vector(_StdTy &&right, const _Alloc &alloc);
#endif//STD_WRAPPER_EXPORT

    ~vector();

    vector &operator=(const _Myt &other);
    vector &operator=(_Myt &&other);
#ifdef STD_WRAPPER_EXPORT
    vector &operator=(const _StdTy &other);
    vector &operator=(_StdTy &&other);
#endif//STD_WRAPPER_EXPORT
    vector &operator=(std::initializer_list<_Ty> ilist);

    void assign(size_type count, const _Ty &value);
#ifdef STD_WRAPPER_EXPORT
    template< class InputIt> void assign(InputIt first, InputIt last) { _vector->assign(first, last); }
#endif//STD_WRAPPER_EXPORT
    void assign(std::initializer_list<_Ty> ilist);

    reference at(size_type pos);
    const_reference at(size_type pos) const;

    reference operator[](size_type pos);
    const_reference operator[](size_type pos) const;

    reference front();
    const_reference front() const;

    reference back();
    const_reference back() const;

    _Ty *data() noexcept;
    const _Ty *data() const noexcept;

    iterator begin() noexcept;
    const_iterator begin() const noexcept;
    const_iterator cbegin() const noexcept;

    iterator end() noexcept;
    const_iterator end() const noexcept;
    const_iterator cend() const noexcept;

    reverse_iterator rbegin() noexcept;
    const_reverse_iterator rbegin() const;
    const_reverse_iterator crbegin() const noexcept;

    reverse_iterator rend() noexcept;
    const_reverse_iterator rend() const noexcept;
    const_reverse_iterator crend() const noexcept;

    bool empty() const noexcept;
    size_type size() const noexcept;
    void reserve(size_type new_cap);
    void clear() noexcept;

    void push_back(const _Ty &value);
    void push_back(_Ty &&value);

    void resize(size_type count);
    void resize(size_type count, const value_type& value);

private:
    std::vector<_Ty, _Alloc> *_vector;
};

std_wrappers \ vector.cpp

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//vector_const_iterator
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class _Myvec, class _IterTy>
vector_const_iterator<_Myvec, _IterTy>::vector_const_iterator(const typename _IterTy &iter) { _iter=new _IterTy(iter); }

template<class _Myvec, class _IterTy>
vector_const_iterator<_Myvec, _IterTy>::vector_const_iterator(const _Myiter &right) { _iter=new _IterTy(*(right._iter)); }

template<class _Myvec, class _IterTy>
vector_const_iterator<_Myvec, _IterTy>::vector_const_iterator(_Myiter &&right) { _iter=right._iter; right._iter=nullptr; }

//template<class _Myvec, class _IterTy>
//vector_const_iterator<_Myvec, _IterTy>::vector_const_iterator(typename _IterTy &&iter):_iter(iter) {}

template<class _Myvec, class _IterTy>
vector_const_iterator<_Myvec, _IterTy>::~vector_const_iterator(){ delete _iter; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator=(const _Myiter &right) { if(_iter==nullptr) _iter=new _IterTy(*(right._iter)); else _iter->operator=(*(right._iter)); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator=(_Myiter &&right) { if(_iter!=nullptr) delete _iter;  _iter=right._iter; right._iter=nullptr; return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::reference vector_const_iterator<_Myvec, _IterTy>::operator*() const { return _iter->operator*(); }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::pointer vector_const_iterator<_Myvec, _IterTy>::operator->() const { return _iter->operator->(); }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator++() { _iter->operator++(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter vector_const_iterator<_Myvec, _IterTy>::operator++(int) { _iter->operator++(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator--() { _iter->operator--(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter vector_const_iterator<_Myvec, _IterTy>::operator--(int) { _iter->operator--(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator+=(difference_type offset) { _iter->operator+=(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter vector_const_iterator<_Myvec, _IterTy>::operator+(difference_type offset) const { _iter->operator+(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter &vector_const_iterator<_Myvec, _IterTy>::operator-=(difference_type offset) { _iter->operator-=(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::_Myiter vector_const_iterator<_Myvec, _IterTy>::operator-(difference_type offset) const { _iter->operator-(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::difference_type vector_const_iterator<_Myvec, _IterTy>::operator-(const _Myiter &right) const { return _iter->operator-(*right._iter); }

template<class _Myvec, class _IterTy>
typename vector_const_iterator<_Myvec, _IterTy>::reference vector_const_iterator<_Myvec, _IterTy>::operator[](difference_type offset) const { return _iter->operator[](offset); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator==(const _Myiter &right) const { return _iter->operator==(*right._iter); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator!=(const _Myiter &right) const { return _iter->operator!=(*right._iter); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator<(const _Myiter &right) const { return _iter->operator<(*right._iter); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator>(const _Myiter &right) const { return _iter->operator>(*right._iter); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator<=(const _Myiter &right) const { return _iter->operator<=(*right._iter); }

template<class _Myvec, class _IterTy>
bool vector_const_iterator<_Myvec, _IterTy>::operator>=(const _Myiter &right) const { return _iter->operator>=(*right._iter); }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//vector_iterator
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class _Myvec, class _IterTy>
vector_iterator<_Myvec, _IterTy>::vector_iterator(const typename _IterTy &iter):vector_const_iterator(iter) {}

template<class _Myvec, class _IterTy>
vector_iterator<_Myvec, _IterTy>::vector_iterator(const _Myiter &right):vector_const_iterator(right) {}

template<class _Myvec, class _IterTy>
vector_iterator<_Myvec, _IterTy>::vector_iterator(_Myiter &&right):vector_const_iterator(right) {}

//template<class _Myvec, class _IterTy>
//vector_iterator<_Myvec, _IterTy>::vector_iterator(typename _IterTy &&iter):vector_const_iterator(iter) {}

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator=(const _Myiter &right) { if(_iter==nullptr) _iter=new _IterTy(*(right._iter)); else _iter->operator=(*(right._iter)); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator=(_Myiter &&right) { if(_iter!=nullptr) delete _iter;  _iter=right._iter; right._iter=nullptr; return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::reference vector_iterator<_Myvec, _IterTy>::operator*() const { return _iter->operator*(); }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::pointer vector_iterator<_Myvec, _IterTy>::operator->() const { return _iter->operator->(); }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator++() { _iter->operator++(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter vector_iterator<_Myvec, _IterTy>::operator++(int) { _iter->operator++(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator--() { _iter->operator--(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter vector_iterator<_Myvec, _IterTy>::operator--(int) { _iter->operator--(); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator+=(difference_type offset) { _iter->operator+=(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter vector_iterator<_Myvec, _IterTy>::operator+(difference_type offset) const { _iter->operator+(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter &vector_iterator<_Myvec, _IterTy>::operator-=(difference_type offset) { _iter->operator-=(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::_Myiter vector_iterator<_Myvec, _IterTy>::operator-(difference_type offset) const { _iter->operator-(offset); return *this; }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::difference_type vector_iterator<_Myvec, _IterTy>::operator-(const _Mybase &right) const { return _iter->operator-(*right._iter); }

template<class _Myvec, class _IterTy>
typename vector_iterator<_Myvec, _IterTy>::reference vector_iterator<_Myvec, _IterTy>::operator[](difference_type offset) const { return _iter->operator[](offset); }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//vector
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector() noexcept { _vector=new std::vector<_Ty, _Alloc>(); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(const _Alloc &alloc) noexcept { _vector=new std::vector<_Ty, _Alloc>(alloc); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(size_type count) { _vector=new std::vector<_Ty, _Alloc>(count); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(size_type count, const value_type &value) { _vector=new std::vector<_Ty, _Alloc>(count, value); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(size_type count, const value_type& value, const _Alloc &alloc) { _vector=new std::vector<_Ty, _Alloc>(count, value, alloc); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(const _Myt &right) { _vector=new std::vector<_Ty, _Alloc>(*(right._vector)); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(const _Myt &right, const _Alloc &alloc) { _vector=new std::vector<_Ty, _Alloc>(*(right._vector), alloc); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(_Myt &&right) noexcept { _vector=right._vector; right._vector=new std::vector<_Ty, _Alloc>();  }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(_Myt &&right, const _Alloc &alloc) { _vector=right._vector; right._vector=new std::vector<_Ty, _Alloc>(alloc); }

#ifdef STD_WRAPPER_EXPORT
template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(const _StdTy &right) { _vector=new std::vector<_Ty, _Alloc>(right); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(const _StdTy &right, const _Alloc &alloc) { _vector=new std::vector<_Ty, _Alloc>(right, alloc); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(_StdTy &&right) noexcept { _vector=new std::vector<_Ty, _Alloc>(right); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(_StdTy &&right, const _Alloc &alloc) { _vector=new std::vector<_Ty, _Alloc>(right, alloc); }
#endif//STD_WRAPPER_EXPORT

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::~vector() { delete _vector; }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(const _Myt &other) { _vector->operator=(*(other._vector)); return *this;}

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(_Myt &&other) { delete _vector; _vector=other._vector; other._vector=new std::vector<_Ty, _Alloc>(); return *this; }

#ifdef STD_WRAPPER_EXPORT
template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(const _StdTy &other) { _vector->operator=(other); return *this; }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(_StdTy &&other) { _vector->operator=(other); return *this; }
#endif//STD_WRAPPER_EXPORT

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(std::initializer_list<_Ty> ilist) { _vector->operator=(ilist); return *this; }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::assign(size_type count, const _Ty &value) { _vector->assign(count, value); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::assign(std::initializer_list<_Ty> ilist) { _vector->assign(ilist); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reference vector<_Ty, _Alloc>::at(size_type pos) { return _vector->at(pos); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reference vector<_Ty, _Alloc>::at(size_type pos) const { return _vector->at(pos); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reference vector<_Ty, _Alloc>::operator[](size_type pos) { return _vector->operator[](pos); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reference vector<_Ty, _Alloc>::operator[](size_type pos) const { return _vector->operator[](pos); };

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reference vector<_Ty, _Alloc>::front() { return _vector->front(); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reference vector<_Ty, _Alloc>::front() const { return _vector->front(); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reference vector<_Ty, _Alloc>::back() { return _vector->back(); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reference vector<_Ty, _Alloc>::back() const { return _vector->back(); }

template<class _Ty, class _Alloc>
_Ty *vector<_Ty, _Alloc>::data() noexcept { return _vector->data(); }

template<class _Ty, class _Alloc>
const _Ty *vector<_Ty, _Alloc>::data() const noexcept { return _vector->data(); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::iterator vector<_Ty, _Alloc>::begin() noexcept { return iterator(_vector->begin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_iterator vector<_Ty, _Alloc>::begin() const noexcept { return const_iterator(_vector->cbegin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_iterator vector<_Ty, _Alloc>::cbegin() const noexcept { return const_iterator(_vector->cbegin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::iterator vector<_Ty, _Alloc>::end() noexcept { return iterator(_vector->end()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_iterator vector<_Ty, _Alloc>::end() const noexcept { return const_iterator(_vector->cend()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_iterator vector<_Ty, _Alloc>::cend() const noexcept { return const_iterator(_vector->cend()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reverse_iterator vector<_Ty, _Alloc>::rbegin() noexcept { return reverse_iterator(_vector->rbegin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reverse_iterator vector<_Ty, _Alloc>::rbegin() const { return const_reverse_iterator(_vector->crbegin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reverse_iterator vector<_Ty, _Alloc>::crbegin() const noexcept { return const_reverse_iterator(_vector->crbegin()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::reverse_iterator vector<_Ty, _Alloc>::rend() noexcept { return reverse_iterator(_vector->rend()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reverse_iterator vector<_Ty, _Alloc>::rend() const noexcept { return const_reverse_iterator(_vector->crend()); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::const_reverse_iterator vector<_Ty, _Alloc>::crend() const noexcept { return const_reverse_iterator(_vector->crend()); }

template<class _Ty, class _Alloc>
bool vector<_Ty, _Alloc>::empty() const noexcept { return _vector->empty(); }

template<class _Ty, class _Alloc>
typename vector<_Ty, _Alloc>::size_type vector<_Ty, _Alloc>::size() const noexcept { return _vector->size(); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::reserve(size_type new_cap) { _vector->reserve(new_cap); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::clear() noexcept { _vector->clear(); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::push_back(const _Ty &value) { _vector->push_back(value); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::push_back(_Ty &&value) { _vector->push_back(value); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::resize(size_type count) { _vector->resize(count); }

template<class _Ty, class _Alloc>
void vector<_Ty, _Alloc>::resize(size_type count, const value_type& value) { _vector->resize(count, value); }

我遗漏了一些函数,因为我不相信我能让它们工作(基本上任何有自己模板的函数)

template< class InputIt > vector( InputIt first, InputIt last, 
    const Allocator& alloc = Allocator() );
template< class InputIt > void assign( InputIt first, InputIt last );

我不得不关注右值参考函数,但我认为我认为它是正确的。

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(vector<_Ty, _Alloc> &&right) noexcept { _vector=right._vector; right._vector=new std::vector<_Ty, _Alloc>();  }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc>::vector(vector<_Ty, _Alloc> &&right, const _Alloc &alloc) { _vector=right._vector; right._vector=new std::vector<_Ty, _Alloc>(alloc); }

template<class _Ty, class _Alloc>
vector<_Ty, _Alloc> &vector<_Ty, _Alloc>::operator=(vector<_Ty, _Alloc> &&other) { delete _vector; _vector=other._vector; other._vector=new std::vector<_Ty, _Alloc>(); return *this; }

我已经在VS2015中编译并运行了这一切,并且所有内容似乎都是kosher(对于其他编译器而言,这并不是很多)。我在显式模板实例化时收到了C4661警告。

opencl_std.h(21): warning C4661: 'void cl::util::vector<std::size_t,std::allocator<std::_Ty>>::resize(unsigned __int64)': no suitable definition provided for explicit template instantiation request

但我认为它纯粹是一个警告,因为它是在实例化发生之前定义的。我期待这条线的C4251警告,

std::vector<_Ty, _Alloc> *_vector;

但我没有看到一个,因为它是一个指针,编译版本应该就其大小达成一致。使用cl :: util :: vector&lt; :: size_t&gt;从图书馆工作正常。我甚至试图使用cl :: util :: vector&lt; :: int&gt;并获得了我预期的链接警告(因为它从未实例化)。我打算用其他一些模板,列表,地图,unordered_map,字符串等来做这件事...只是在寻找一个检查我是否错过了什么。

修改 将此添加到github repo并在我完成包装器时将其更新

0 个答案:

没有答案