2
0
mirror of https://github.com/boostorg/ublas.git synced 2026-01-21 17:32:20 +00:00
Files
ublas/test/minimal_allocator_test.cpp
2020-11-27 11:49:21 -05:00

52 lines
1.1 KiB
C++

/*
Copyright 2020 Glen Joseph Fernandes
(glenjofe@gmail.com)
Distributed under the Boost Software License, Version 1.0.
(http://www.boost.org/LICENSE_1_0.txt)
*/
#include <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/numeric/ublas/matrix.hpp>
#include <new>
template<class T>
struct Allocator {
typedef T value_type;
Allocator() BOOST_NOEXCEPT { }
template<class U>
Allocator(const Allocator<U>&) BOOST_NOEXCEPT { }
T* allocate(std::size_t size) {
return static_cast<T*>(::operator new(sizeof(T) * size));
}
void deallocate(T* ptr, std::size_t) {
::operator delete(ptr);
}
};
template<class T, class U>
bool operator==(const Allocator<T>&, const Allocator<U>&) BOOST_NOEXCEPT
{
return true;
}
template<class T, class U>
bool operator!=(const Allocator<T>&, const Allocator<U>&) BOOST_NOEXCEPT
{
return false;
}
int main()
{
boost::numeric::ublas::matrix<int,
boost::numeric::ublas::row_major,
boost::numeric::ublas::unbounded_array<int,
Allocator<int> > > matrix(4, 4);
matrix(1, 2) = 3;
}
#endif