Gistrec icon

Nano STL Allocator

Gistrec | PRO | 05/03/20 12:55:16 PM UTC | 0 ⭐ | 808 👁️ | Never ⏰ | []
C++ |

1.11 KB

|

None

|

0 👍

/

0 👎

#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_

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎