libs/capy/include/boost/capy/detail/run.hpp
100.0% Lines (4/4)
100.0% Functions (2/2)
-% Branches (0/0)
libs/capy/include/boost/capy/detail/run.hpp
| Line | Hits | Source Code |
|---|---|---|
| 1 | // | |
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com) | |
| 3 | // | |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 6 | // | |
| 7 | // Official repository: https://github.com/cppalliance/capy | |
| 8 | // | |
| 9 | ||
| 10 | #ifndef BOOST_CAPY_DETAIL_RUN_HPP | |
| 11 | #define BOOST_CAPY_DETAIL_RUN_HPP | |
| 12 | ||
| 13 | #include <boost/capy/detail/config.hpp> | |
| 14 | #include <boost/capy/detail/frame_memory_resource.hpp> | |
| 15 | ||
| 16 | #include <cstddef> | |
| 17 | #include <memory_resource> | |
| 18 | ||
| 19 | namespace boost { | |
| 20 | namespace capy { | |
| 21 | namespace detail { | |
| 22 | ||
| 23 | /// Concept for standard Allocator types. | |
| 24 | template<class A> | |
| 25 | concept Allocator = requires(A a, std::size_t n) { | |
| 26 | typename A::value_type; | |
| 27 | { a.allocate(n) } -> std::same_as<typename A::value_type*>; | |
| 28 | }; | |
| 29 | ||
| 30 | /// Specialization for memory_resource* - stores pointer directly. | |
| 31 | template<> | |
| 32 | class frame_memory_resource<std::pmr::memory_resource*> | |
| 33 | { | |
| 34 | std::pmr::memory_resource* mr_; | |
| 35 | ||
| 36 | public: | |
| 37 | 5 | explicit frame_memory_resource(std::pmr::memory_resource* mr) noexcept |
| 38 | 5 | : mr_(mr) |
| 39 | { | |
| 40 | 5 | } |
| 41 | ||
| 42 | 5 | std::pmr::memory_resource* get() noexcept { return mr_; } |
| 43 | }; | |
| 44 | ||
| 45 | /// Specialization for void - no allocator (empty). | |
| 46 | template<> | |
| 47 | class frame_memory_resource<void> | |
| 48 | { | |
| 49 | public: | |
| 50 | frame_memory_resource() = default; | |
| 51 | ||
| 52 | std::pmr::memory_resource* get() noexcept { return nullptr; } | |
| 53 | }; | |
| 54 | ||
| 55 | } // namespace detail | |
| 56 | } // namespace capy | |
| 57 | } // namespace boost | |
| 58 | ||
| 59 | #endif | |
| 60 |