head	1.2;
access;
symbols
	RELENG_9_1_0_RELEASE:1.2.2.2
	RELENG_9_1:1.2.2.2.0.2
	RELENG_9_1_BP:1.2.2.2
	RELENG_9:1.2.0.2;
locks; strict;
comment	@# @;


1.2
date	2012.03.14.00.09.36;	author theraven;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2011.11.25.20.59.04;	author theraven;	state Exp;
branches;
next	;

1.2.2.1
date	2012.05.22.18.30.14;	author theraven;	state dead;
branches;
next	1.2.2.2;

1.2.2.2
date	2012.05.22.18.30.14;	author theraven;	state Exp;
branches;
next	;


desc
@@


1.2
log
@SVN rev 232950 on 2012-03-14 00:09:36Z by theraven

Import new versions of libcxxrt and libc++.
Please tests any C++ code you care about with -stdlib=libc++!

Approved by:	dim (mentor)
@
text
@// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___SSO_ALLOCATOR
#define _LIBCPP___SSO_ALLOCATOR

#include <__config>
#include <type_traits>
#include <new>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Tp, size_t _Np> class _LIBCPP_HIDDEN __sso_allocator;

template <size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator<void, _Np>
{
public:
    typedef const void*       const_pointer;
    typedef void              value_type;
};

template <class _Tp, size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator
{
    typename aligned_storage<sizeof(_Tp) * _Np>::type buf_;
    bool __allocated_;
public:
    typedef size_t            size_type;
    typedef _Tp*              pointer;
    typedef _Tp               value_type;

    _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
    _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
    template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
         : __allocated_(false) {}
private:
    __sso_allocator& operator=(const __sso_allocator&);
public:
    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = 0)
    {
        if (!__allocated_ && __n <= _Np)
        {
            __allocated_ = true;
            return (pointer)&buf_;
        }
        return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));
    }
    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
    {
        if (__p == (pointer)&buf_)
            __allocated_ = false;
        else
            ::operator delete(__p);
    }
    _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}

    _LIBCPP_INLINE_VISIBILITY
    bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}
    _LIBCPP_INLINE_VISIBILITY
    bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;}
};

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP___SSO_ALLOCATOR
@


1.2.2.1
log
@file __sso_allocator was added on branch RELENG_9 on 2012-05-22 18:32:26 +0000
@
text
@d1 77
@


1.2.2.2
log
@SVN rev 235798 on 2012-05-22 18:30:14Z by theraven

Merged libcxxrt and libc++.  Now available for testing on 9-stable with
-stdlib=libc++.  Changes to libstdc++ not yet merged, so it is not yet possible
to mix libstdc++ and libc++ in the same program.

Merged revisions: 226702,226785,227006,227755,227983,227987,228531,228630,228761,229067,230127,232950,233098,234715-234716,234772
@
text
@a0 77
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___SSO_ALLOCATOR
#define _LIBCPP___SSO_ALLOCATOR

#include <__config>
#include <type_traits>
#include <new>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

template <class _Tp, size_t _Np> class _LIBCPP_HIDDEN __sso_allocator;

template <size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator<void, _Np>
{
public:
    typedef const void*       const_pointer;
    typedef void              value_type;
};

template <class _Tp, size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator
{
    typename aligned_storage<sizeof(_Tp) * _Np>::type buf_;
    bool __allocated_;
public:
    typedef size_t            size_type;
    typedef _Tp*              pointer;
    typedef _Tp               value_type;

    _LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
    _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
    template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
         : __allocated_(false) {}
private:
    __sso_allocator& operator=(const __sso_allocator&);
public:
    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = 0)
    {
        if (!__allocated_ && __n <= _Np)
        {
            __allocated_ = true;
            return (pointer)&buf_;
        }
        return static_cast<pointer>(::operator new(__n * sizeof(_Tp)));
    }
    _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type)
    {
        if (__p == (pointer)&buf_)
            __allocated_ = false;
        else
            ::operator delete(__p);
    }
    _LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}

    _LIBCPP_INLINE_VISIBILITY
    bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}
    _LIBCPP_INLINE_VISIBILITY
    bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;}
};

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP___SSO_ALLOCATOR
@


1.1
log
@SVN rev 227983 on 2011-11-25 20:59:04Z by theraven

Import libc++ / libcxxrt into base.  Not build by default yet (use
MK_LIBCPLUSPLUS=yes to enable).  This is a work-in-progress.  It works for
me, but is not guaranteed to work for anyone else and may eat your dog.

To build C++ using libc++, add -stdlib=libc++ to your CXX and LD flags.

Bug reports welcome, bug fixes even more welcome...

Approved by:	dim (mentor)
@
text
@d24 1
a24 1
template <class _Tp, size_t _N> class _LIBCPP_HIDDEN __sso_allocator;
d26 2
a27 2
template <size_t _N>
class _LIBCPP_HIDDEN __sso_allocator<void, _N>
d34 1
a34 1
template <class _Tp, size_t _N>
d37 1
a37 1
    typename aligned_storage<sizeof(_Tp) * _N>::type buf_;
d46 1
a46 1
    template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _N>&) throw()
d51 1
a51 1
    _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _N>::const_pointer = 0)
d53 1
a53 1
        if (!__allocated_ && __n <= _N)
@

