Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef NANOSTL_ALLOCATOR_H_
- #define NANOSTL_ALLOCATOR_H_
- #ifdef NANOSTL_DEBUG
- #include <iostream>
- #endif
- namespace nanostl {
- typedef unsigned long long size_type;
- #ifdef __clang__
- #pragma clang diagnostic push
- #if __has_warning("-Wzero-as-null-pointer-constant")
- #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
- #endif
- #endif
- ///
- /// allocator class implementaion without libc function
- ///
- template <typename T>
- class allocator {
- public:
- typedef T value_type;
- typedef T* pointer;
- typedef const T* const_pointer;
- typedef T& reference;
- typedef const T& const_reference;
- allocator() {}
- T* allocate(size_type n, const void* hint = 0) {
- (void)hint; // Ignore `hint' for a while.
- if (n < 1) {
- return 0;
- }
- #ifdef NANOSTL_DEBUG
- std::cerr << "allocator::allocate: n " << n << std::endl;
- #endif
- return new T[n];
- }
- void deallocate(T* p, size_type n) {
- (void)n;
- delete[] p;
- }
- private:
- };
- #ifdef __clang__
- #pragma clang diagnostic pop
- #endif
- } // namespace nanostl
- #endif // NANOSTL_ALLOCATOR_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement