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

[INFRA] Update contrib/std #3261

Merged
merged 3 commits into from
Jul 2, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
Copyright (c) 2006-2024, Knut Reinert & Freie Universität Berlin
Copyright (c) 2016-2024, Knut Reinert & MPI für molekulare Genetik
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
11 changes: 11 additions & 0 deletions include/seqan3/contrib/std/LICENSES/BSD-3-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Copyright (c) <year> <owner>.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156 changes: 156 additions & 0 deletions include/seqan3/contrib/std/LICENSES/CC-BY-4.0.txt

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions include/seqan3/contrib/std/LICENSES/CC0-1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Creative Commons Legal Code

CC0 1.0 Universal

CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.

For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:

i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.

4. Limitations and Disclaimers.

a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
8 changes: 5 additions & 3 deletions include/seqan3/contrib/std/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
# SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
# SPDX-License-Identifier: CC-BY-4.0
<!--
SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
SPDX-License-Identifier: CC-BY-4.0
-->

# seqan-std
Implementation of several C++23 views
232 changes: 232 additions & 0 deletions include/seqan3/contrib/std/chunk_by_view.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
// SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin
// SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik
// SPDX-License-Identifier: BSD-3-Clause

/*!\file
* \author Enrico Seiler <enrico.seiler AT fu-berlin.de>
* \brief Provides seqan::stl::views::chunk_by.
*/

// File might be included from multiple libraries.
#ifndef SEQAN_STD_CHUNK_BY_VIEW
#define SEQAN_STD_CHUNK_BY_VIEW

#include <algorithm>
#include <cassert>
#include <ranges>

#ifdef __cpp_lib_ranges_chunk_by

namespace seqan::stl::views
{

using std::ranges::views::chunk_by;

} // namespace seqan::stl::views

#else

# include "all_view.hpp"
# include "concepts.hpp"
# include "detail/adaptor_from_functor.hpp"
# include "detail/compiler_definitions.hpp"
# include "detail/movable_box.hpp"
# include "detail/non_propagating_cache.hpp"

namespace seqan::stl::ranges
{

template <std::ranges::forward_range V,
std::indirect_binary_predicate<std::ranges::iterator_t<V>, std::ranges::iterator_t<V>> Pred>
requires std::ranges::view<V> && std::is_object_v<Pred>
class chunk_by_view : public std::ranges::view_interface<chunk_by_view<V, Pred>>
{
private:
V base_ = V();
seqan::stl::detail::movable_box<Pred> pred_;
class iterator;

seqan::stl::detail::non_propagating_cache<std::ranges::iterator_t<V>> current_;

constexpr std::ranges::iterator_t<V> find_next(std::ranges::iterator_t<V> current)
{
assert(pred_.has_value());
auto pred = [this]<typename lhs_t, typename rhs_t>(lhs_t && lhs, rhs_t && rhs)
{
// Call pred with two arguments, return logical not.
return !bool((*pred_)(std::forward<lhs_t>(lhs), std::forward<rhs_t>(rhs)));
};
auto it = std::ranges::adjacent_find(current, std::ranges::end(base_), pred);
return std::ranges::next(it, 1, std::ranges::end(base_));
}

constexpr std::ranges::iterator_t<V> find_prev(std::ranges::iterator_t<V> current)
requires std::ranges::bidirectional_range<V>
{
assert(pred_.has_value());
auto pred = [this]<typename lhs_t, typename rhs_t>(lhs_t && lhs, rhs_t && rhs)
{
// Call pred with two (reversed) arguments, return logical not.
return !bool((*pred_)(std::forward<rhs_t>(rhs), std::forward<lhs_t>(lhs)));
};
auto rbegin = std::make_reverse_iterator(current);
auto rend = std::make_reverse_iterator(std::ranges::begin(base_));
assert(rbegin != rend);
auto it = std::ranges::adjacent_find(rbegin, rend, pred).base();
return std::ranges::prev(it, 1, std::ranges::begin(base_));
}

public:
chunk_by_view()
requires std::default_initializable<V> && std::default_initializable<Pred>
= default;

constexpr explicit chunk_by_view(V base, Pred pred) : base_{std::move(base)}, pred_{std::move(pred)}
{}

constexpr V base() const &
requires std::copy_constructible<V>
{
return base_;
}
constexpr V base() &&
{
return std::move(base_);
}

constexpr Pred const & pred() const
{
return *pred_;
}

constexpr iterator begin()
{
assert(pred_.has_value());
std::ranges::iterator_t<V> it;
if (current_.has_value())
{
it = current_.value();
}
else
{
it = find_next(std::ranges::begin(base_));
current_ = it;
}

return iterator{*this, std::ranges::begin(base_), it};
}
constexpr auto end()
{
if constexpr (std::ranges::common_range<V>)
{
return iterator{*this, std::ranges::end(base_), std::ranges::end(base_)};
}
else
{
return std::default_sentinel;
}
}
};

template <class R, class Pred>
chunk_by_view(R &&, Pred) -> chunk_by_view<seqan::stl::views::all_t<R>, Pred>;

template <std::ranges::forward_range V,
std::indirect_binary_predicate<std::ranges::iterator_t<V>, std::ranges::iterator_t<V>> Pred>
requires std::ranges::view<V> && std::is_object_v<Pred>
class chunk_by_view<V, Pred>::iterator
{
private:
chunk_by_view * parent_ = nullptr;
std::ranges::iterator_t<V> current_ = std::ranges::iterator_t<V>{};
std::ranges::iterator_t<V> next_ = std::ranges::iterator_t<V>{};

constexpr iterator(chunk_by_view & parent, std::ranges::iterator_t<V> current, std::ranges::iterator_t<V> next) :
parent_{std::addressof(parent)},
current_{std::move(current)},
next_{std::move(next)}
{}

friend chunk_by_view;

public:
using value_type = std::ranges::subrange<std::ranges::iterator_t<V>>;
using difference_type = std::ranges::range_difference_t<V>;
using iterator_category = std::input_iterator_tag;
using iterator_concept = std::conditional_t<std::ranges::bidirectional_range<V>, //
std::bidirectional_iterator_tag,
std::forward_iterator_tag>;

iterator() = default;

constexpr value_type operator*() const
{
assert(current_ != next_);
return std::ranges::subrange{current_, next_};
}
constexpr iterator & operator++()
{
assert(current_ != next_);
current_ = next_;
next_ = parent_->find_next(current_);
return *this;
}
constexpr iterator operator++(int)
{
auto tmp = *this;
++*this;
return tmp;
}

constexpr iterator & operator--()
requires std::ranges::bidirectional_range<V>
{
next_ = current_;
current_ = parent_->find_prev(next_);
return *this;
}
constexpr iterator operator--(int)
requires std::ranges::bidirectional_range<V>
{
auto tmp = *this;
--*this;
return tmp;
}

friend constexpr bool operator==(iterator const & x, iterator const & y)
{
return x.current_ == y.current_;
}
friend constexpr bool operator==(iterator const & x, std::default_sentinel_t)
{
return x.current_ == x.next_;
}
};

struct chunk_by_fn
{
template <typename Predicate>
constexpr auto operator()(Predicate && pred) const
{
return seqan::stl::detail::adaptor_from_functor{*this, std::forward<Predicate>(pred)};
}

template <seqan::stl::ranges::viewable_range Range, typename Predicate>
constexpr auto operator()(Range && range, Predicate && pred) const
{
return chunk_by_view{std::forward<Range>(range), std::forward<Predicate>(pred)};
}
};

} // namespace seqan::stl::ranges

namespace seqan::stl::views
{

inline constexpr auto chunk_by = seqan::stl::ranges::chunk_by_fn{};

} // namespace seqan::stl::views

#endif // ifdef __cpp_lib_ranges_chunk_by

#endif // SEQAN_STD_CHUNK_BY_VIEW
Loading
Loading