Skip to content

Commit

Permalink
Move constify_t under metaprog utilities (#19)
Browse files Browse the repository at this point in the history
* Move `constify_t` under metaprog utilities

Signed-off-by: Julien Jerphanion <[email protected]>

* Rename `sparrow::impl` to `sparrow:mpl`

Signed-off-by: Julien Jerphanion <[email protected]>

Co-authored-by: Johan Mabille <[email protected]>

---------

Signed-off-by: Julien Jerphanion <[email protected]>
Co-authored-by: Johan Mabille <[email protected]>
  • Loading branch information
jjerphan and JohanMabille authored Mar 13, 2024
1 parent 709f48a commit a2d18e5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ set(SPARROW_HEADERS
${SPARROW_INCLUDE_DIR}/sparrow/data_type.hpp
${SPARROW_INCLUDE_DIR}/sparrow/dynamic_bitset.hpp
${SPARROW_INCLUDE_DIR}/sparrow/iterator.hpp
${SPARROW_INCLUDE_DIR}/sparrow/mp_utils.hpp
${SPARROW_INCLUDE_DIR}/sparrow/sparrow_version.hpp
)

Expand Down
34 changes: 11 additions & 23 deletions include/sparrow/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,17 @@
#include <concepts>
#include <cstdint>

#include "sparrow/mp_utils.hpp"
#include "sparrow/iterator.hpp"

namespace sparrow
{
namespace impl
{
// TODO: Should probably move to a MP util file
template <class T, bool is_const>
struct constify
: std::conditional<is_const, const T, T>
{
};

template <class T, bool is_const>
using constify_t = typename constify<T, is_const>::type;
}

template <class T, bool is_const>
class buffer_iterator
: public iterator_base
<
buffer_iterator<T, is_const>,
impl::constify_t<T, is_const>,
mpl::constify_t<T, is_const>,
std::contiguous_iterator_tag
>
{
Expand All @@ -51,7 +39,7 @@ namespace sparrow
using base_type = iterator_base
<
self_type,
impl::constify_t<T, is_const>,
mpl::constify_t<T, is_const>,
std::contiguous_iterator_tag
>;
using pointer = typename base_type::pointer;
Expand Down Expand Up @@ -115,7 +103,7 @@ namespace sparrow

reference back();
const_reference back() const;

template <class U = T>
U* data() noexcept;

Expand All @@ -140,7 +128,7 @@ namespace sparrow

void swap(buffer_base& rhs) noexcept;
bool equal(const buffer_base& rhs) const;

protected:

buffer_base() = default;
Expand All @@ -163,7 +151,7 @@ namespace sparrow

template <class T>
bool operator==(const buffer_base<T>& lhs, const buffer_base<T>& rhs);

/**
* @class buffer
* @brief Object that owns a piece of contiguous memory
Expand All @@ -182,9 +170,9 @@ namespace sparrow
explicit buffer(size_type size);
buffer(size_type size, value_type);
buffer(pointer data, size_type size);

~buffer();

buffer(const buffer&);
buffer& operator=(const buffer&);

Expand Down Expand Up @@ -476,13 +464,13 @@ namespace sparrow
: base_type{data, size}
{
}

template <class T>
buffer<T>::~buffer()
{
deallocate(base_type::data());
}

template <class T>
buffer<T>::buffer(const buffer<T>& rhs)
: base_type{allocate(rhs.size()), rhs.size()}
Expand Down Expand Up @@ -544,7 +532,7 @@ namespace sparrow
{
resize(size_type(0));
}

template <class T>
auto buffer<T>::allocate(size_type size) const -> pointer
{
Expand Down
32 changes: 32 additions & 0 deletions include/sparrow/mp_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 Man Group Operations Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <iterator>

namespace sparrow
{
namespace mpl
{
template <class T, bool is_const>
struct constify
: std::conditional<is_const, const T, T>
{
};

template <class T, bool is_const>
using constify_t = typename constify<T, is_const>::type;
}
}

0 comments on commit a2d18e5

Please sign in to comment.