// // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // Official repository: https://github.com/boostorg/json // #ifndef BOOST_JSON_DETAIL_STACK_HPP #define BOOST_JSON_DETAIL_STACK_HPP #include #include #include #include #include namespace boost { namespace json { namespace detail { #if defined( BOOST_LIBSTDCXX_VERSION ) && BOOST_LIBSTDCXX_VERSION < 50000 template struct is_trivially_copy_assignable : mp11::mp_bool< std::is_copy_assignable::value && std::has_trivial_copy_assign::value > {}; #else using std::is_trivially_copy_assignable; #endif class stack { template< class T = void > struct non_trivial; storage_ptr sp_; std::size_t cap_ = 0; std::size_t size_ = 0; non_trivial<>* head_ = nullptr; unsigned char* base_ = nullptr; unsigned char* buf_ = nullptr; public: BOOST_JSON_DECL ~stack(); stack() = default; stack( storage_ptr sp, unsigned char* buf, std::size_t buf_size) noexcept; bool empty() const noexcept { return size_ == 0; } BOOST_JSON_DECL void clear() noexcept; void reserve(std::size_t n) { if(n > cap_) reserve_impl(n); } template void push(T&& t) { using U = remove_cvref; push( static_cast(t), is_trivially_copy_assignable() ); } template void push_unchecked( T const& t); template void peek(T& t); template void pop(T& t) { using U = remove_cvref; pop( t, is_trivially_copy_assignable() ); } private: template void push( T const& t, std::true_type); template void push( T&& t, std::false_type); template void pop( T& t, std::true_type); template void pop( T& t, std::false_type); BOOST_JSON_DECL void reserve_impl( std::size_t n); }; } // detail } // namespace json } // namespace boost #include #endif