Skip to content

Commit 18c8a34

Browse files
committed
Make cartesian_product specializations a common range
1 parent 4048911 commit 18c8a34

File tree

1 file changed

+25
-87
lines changed

1 file changed

+25
-87
lines changed

include/cartesian_product.hpp

Lines changed: 25 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,23 +1413,6 @@ namespace tl {
14131413
template <bool Const>
14141414
class cursor;
14151415

1416-
//Wraps the end iterator for the 0th range.
1417-
//This is all that's required because the cursor will only ever set the 0th iterator to end when
1418-
//the cartesian product operation has completed.
1419-
template <bool Const>
1420-
class sentinel {
1421-
1422-
public:
1423-
sentinel() = default;
1424-
1425-
//const-converting constructor
1426-
constexpr sentinel(sentinel<!Const> other) requires Const
1427-
{}
1428-
1429-
template <bool>
1430-
friend class cursor;
1431-
};
1432-
14331416
template <bool Const>
14341417
class cursor {
14351418
W x_i, y_i, z_i, x_0, y_0, z_0;
@@ -1494,10 +1477,6 @@ namespace tl {
14941477
return x_i == rhs.x_i && y_i == rhs.y_i && z_i == rhs.z_i;
14951478
}
14961479

1497-
constexpr bool equal(const sentinel<Const>& s) const {
1498-
return x_i == (x_0 + nx) && y_i == (y_0 + ny) && z_i == z_0;
1499-
}
1500-
15011480
constexpr auto distance_to(cursor const& other) const {
15021481
auto idx = linear();
15031482
auto oidx = other.linear();
@@ -1528,21 +1507,21 @@ namespace tl {
15281507
return basic_iterator{ cursor<true>(x_b, y_b, z_b, nx, ny, nz) };
15291508
}
15301509

1531-
constexpr auto end() {
1532-
return sentinel<false>();
1533-
}
1534-
1535-
constexpr auto end() const {
1536-
return sentinel<true>();
1537-
}
1538-
15391510
constexpr auto size() {
15401511
return nx * ny * nz;
15411512
}
15421513

15431514
constexpr auto size() const {
15441515
return nx * ny * nz;
15451516
}
1517+
1518+
constexpr auto end() {
1519+
return begin() + size();
1520+
}
1521+
1522+
constexpr auto end() const {
1523+
return begin() + size();
1524+
}
15461525
};
15471526

15481527
template <typename W, typename B>
@@ -1570,23 +1549,6 @@ namespace tl {
15701549
template <bool Const>
15711550
class cursor;
15721551

1573-
//Wraps the end iterator for the 0th range.
1574-
//This is all that's required because the cursor will only ever set the 0th iterator to end when
1575-
//the cartesian product operation has completed.
1576-
template <bool Const>
1577-
class sentinel {
1578-
1579-
public:
1580-
sentinel() = default;
1581-
1582-
//const-converting constructor
1583-
constexpr sentinel(sentinel<!Const> other) requires Const
1584-
{}
1585-
1586-
template <bool>
1587-
friend class cursor;
1588-
};
1589-
15901552
template <bool Const>
15911553
class cursor {
15921554
W x_i, y_i, x_0, y_0;
@@ -1641,10 +1603,6 @@ namespace tl {
16411603
return x_i == rhs.x_i && y_i == rhs.y_i;
16421604
}
16431605

1644-
constexpr bool equal(const sentinel<Const>& s) const {
1645-
return x_i == (x_0 + nx) && y_i == y_0;
1646-
}
1647-
16481606
constexpr auto distance_to(cursor const& other) const {
16491607
auto idx = linear();
16501608
auto oidx = other.linear();
@@ -1672,21 +1630,22 @@ namespace tl {
16721630
return basic_iterator{ cursor<true>(x_b, y_b, nx, ny) };
16731631
}
16741632

1675-
constexpr auto end() {
1676-
return sentinel<false>();
1677-
}
1678-
1679-
constexpr auto end() const {
1680-
return sentinel<true>();
1681-
}
1682-
16831633
constexpr auto size() {
16841634
return nx * ny;
16851635
}
16861636

16871637
constexpr auto size() const {
16881638
return nx * ny;
16891639
}
1640+
1641+
constexpr auto end() {
1642+
return begin() + size();
1643+
}
1644+
1645+
constexpr auto end() const {
1646+
return begin() + size();
1647+
}
1648+
16901649
};
16911650

16921651
template <typename W, typename B>
@@ -1705,23 +1664,6 @@ namespace tl {
17051664
template <bool Const>
17061665
class cursor;
17071666

1708-
//Wraps the end iterator for the 0th range.
1709-
//This is all that's required because the cursor will only ever set the 0th iterator to end when
1710-
//the cartesian product operation has completed.
1711-
template <bool Const>
1712-
class sentinel {
1713-
1714-
public:
1715-
sentinel() = default;
1716-
1717-
//const-converting constructor
1718-
constexpr sentinel(sentinel<!Const> other) requires Const
1719-
{}
1720-
1721-
template <bool>
1722-
friend class cursor;
1723-
};
1724-
17251667
template <bool Const>
17261668
class cursor {
17271669
long x_i, x_e;
@@ -1757,10 +1699,6 @@ namespace tl {
17571699
return x_i == rhs.x_i;
17581700
}
17591701

1760-
constexpr bool equal(const sentinel<Const>&) const {
1761-
return x_i == x_e;
1762-
}
1763-
17641702
constexpr auto distance_to(cursor const& other) const {
17651703
return static_cast<difference_type>(other.x_i - x_i);
17661704
}
@@ -1783,21 +1721,21 @@ namespace tl {
17831721
return basic_iterator{ cursor<true>(x_i, x_e) };
17841722
}
17851723

1786-
constexpr auto end() {
1787-
return sentinel<false>();
1788-
}
1789-
1790-
constexpr auto end() const {
1791-
return sentinel<true>();
1792-
}
1793-
17941724
constexpr auto size() {
17951725
return x_e - x_i;
17961726
}
17971727

17981728
constexpr auto size() const {
17991729
return x_e - x_i;
18001730
}
1731+
1732+
constexpr auto end() {
1733+
return begin() + size();
1734+
}
1735+
1736+
constexpr auto end() const {
1737+
return begin() + size();
1738+
}
18011739
};
18021740
#endif // DISABLE_CART_PROD_IOTA_SPEC
18031741

0 commit comments

Comments
 (0)