Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move constify_t under metaprog utilities #19

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading