`cardinality`'s return type can't represent the number of elements of large containers
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start by locating the implementation and tests for cardinality in the Boost ICL repository, then trace how it counts elements and chooses its return type. The issue establishes that a closed interval from 0 through SIZE_MAX produces an unrepresentable count, but leaves the API behavior undecided among a precondition, an exception, or saturation. Done means the API decision is made and the resulting behavior is covered by tests.
Written by the indexing model from the issue text.
Description
Consider https://godbolt.org/z/nooz8adKa:
#include <boost/icl/interval_set.hpp>
#include <climits>
#include <iostream>
namespace icl = boost::icl;
int main()
{
icl::interval_set<std::size_t> s;
s.insert(icl::interval<std::size_t>::closed(0, SIZE_MAX));
std::cout << s.empty() << "\n"; // outputs 0
std::cout << cardinality(s) << "\n"; // outputs 0
}
s has SIZE_MAX + 1 elements, which can't be represented by s's size_type (std::size_t). This is a fundamental problem with cardinality's API, not an implementation bug; in particular, #60 does not solve this issue. Possible API-changing solutions are:
- Require as a precondition to calling
cardinalitythat the number of elements not be greater thanstd::numeric_limits<size_t>::max(). - Throw
std::length_errorwhen the number of elements exceedsstd::numeric_limits<size_t>::max(). - Saturate the returned value at
std::numeric_limits<size_t>::max().
- Dominant language
- C++
- Stars
- 15
- Forks
- 51
- Avg merge
- 8d 6h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/icl
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
sprintf deprecatedOpen
Difficulty 1/5 Under an hour Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
-
`touches` is poorly specifiedPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day