• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2020 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4 
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #include <boost/config.hpp>
9 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
10 #include <boost/numeric/ublas/matrix.hpp>
11 #include <new>
12 
13 template<class T>
14 struct Allocator {
15     typedef T value_type;
16 
AllocatorAllocator17     Allocator() BOOST_NOEXCEPT { }
18 
19     template<class U>
AllocatorAllocator20     Allocator(const Allocator<U>&) BOOST_NOEXCEPT { }
21 
allocateAllocator22     T* allocate(std::size_t size) {
23         return static_cast<T*>(::operator new(sizeof(T) * size));
24     }
25 
deallocateAllocator26     void deallocate(T* ptr, std::size_t) {
27         ::operator delete(ptr);
28     }
29 };
30 
31 template<class T, class U>
operator ==(const Allocator<T> &,const Allocator<U> &)32 bool operator==(const Allocator<T>&, const Allocator<U>&) BOOST_NOEXCEPT
33 {
34     return true;
35 }
36 
37 template<class T, class U>
operator !=(const Allocator<T> &,const Allocator<U> &)38 bool operator!=(const Allocator<T>&, const Allocator<U>&) BOOST_NOEXCEPT
39 {
40     return false;
41 }
42 
main()43 int main()
44 {
45     boost::numeric::ublas::matrix<int,
46         boost::numeric::ublas::row_major,
47         boost::numeric::ublas::unbounded_array<int,
48         Allocator<int> > > matrix(4, 4);
49     matrix(1, 2) = 3;
50 }
51 #endif
52