1
1
/* A view of a path to something
2
- (C) 2017-2022 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
2
+ (C) 2017-2024 Niall Douglas <http://www.nedproductions.biz/> (20 commits)
3
3
File Created: Jul 2017
4
4
5
5
@@ -219,15 +219,20 @@ namespace detail
219
219
class path_view ;
220
220
class path_view_component ;
221
221
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator ==(path_view_component x, path_view_component y) noexcept ;
222
+ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator ==(path_view x, path_view y) noexcept ;
223
+ #if __cplusplus >= 202000L || _HAS_CXX20
224
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view_component x, path_view_component y) noexcept ;
225
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view x, path_view y) noexcept ;
226
+ #else
222
227
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view_component x, path_view_component y) noexcept ;
223
228
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator <(path_view_component x, path_view_component y) noexcept ;
229
+ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view x, path_view y) noexcept ;
230
+ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator <(path_view x, path_view y) noexcept ;
231
+ #endif
224
232
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view_component x) noexcept ;
225
233
template <class F > inline LLFIO_PATH_VIEW_CONSTEXPR auto visit (path_view_component view, F &&f);
226
234
template <class F > inline LLFIO_PATH_VIEW_CONSTEXPR auto visit (F &&f, path_view_component view);
227
235
inline std::ostream &operator <<(std::ostream &s, const path_view_component &v);
228
- inline LLFIO_PATH_VIEW_CONSTEXPR bool operator ==(path_view x, path_view y) noexcept ;
229
- inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view x, path_view y) noexcept ;
230
- inline LLFIO_PATH_VIEW_CONSTEXPR bool operator <(path_view x, path_view y) noexcept ;
231
236
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view x) noexcept ;
232
237
233
238
/* ! \class path_view_component
@@ -238,21 +243,11 @@ class LLFIO_DECL path_view_component
238
243
friend class path_view ;
239
244
friend class detail ::path_view_iterator;
240
245
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator ==(path_view_component x, path_view_component y) noexcept ;
246
+ #if __cplusplus >= 202000L || _HAS_CXX20
247
+ friend inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view_component x, path_view_component y) noexcept ;
248
+ #else
241
249
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator !=(path_view_component x, path_view_component y) noexcept ;
242
250
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator <(path_view_component x, path_view_component y) noexcept ;
243
- #if __cplusplus >= 202000L || _HAS_CXX20
244
- friend inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view_component x, path_view_component y) noexcept
245
- {
246
- if (x == y)
247
- {
248
- return std::strong_ordering::equal;
249
- }
250
- if (x < y)
251
- {
252
- return std::strong_ordering::less;
253
- }
254
- return std::strong_ordering::greater;
255
- }
256
251
#endif
257
252
friend inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view_component x) noexcept ;
258
253
template <class F > friend inline LLFIO_PATH_VIEW_CONSTEXPR auto LLFIO_V2_NAMESPACE::visit (path_view_component view, F &&f);
@@ -1598,6 +1593,7 @@ class LLFIO_DECL path_view_component
1598
1593
};
1599
1594
static_assert (std::is_trivially_copyable<path_view_component>::value, " path_view_component is not trivially copyable!" );
1600
1595
static_assert (sizeof (path_view_component) == 3 * sizeof(void *), "path_view_component is not three pointers in size!");
1596
+
1601
1597
// ! \brief Compares **identity** equality not equivalence i.e. backing storage type must be identical, and backing bytes must be identical. Use `compare()` if
1602
1598
// ! you want something stronger.
1603
1599
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator ==(path_view_component x, path_view_component y) noexcept
@@ -1635,6 +1631,106 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator==(path_view_component x, path_vie
1635
1631
const auto bytes = (x._wchar || x._utf16 ) ? (x._length * 2 ) : x._length ;
1636
1632
return 0 == memcmp (x._bytestr , y._bytestr , bytes);
1637
1633
}
1634
+ LLFIO_TEMPLATE (class CharT )
1635
+ LLFIO_TREQUIRES (LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1636
+ inline constexpr bool operator ==(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1637
+ {
1638
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator== with path_view_component and a string literal, use .compare<>()" );
1639
+ return false ;
1640
+ }
1641
+ LLFIO_TEMPLATE (class CharT )
1642
+ LLFIO_TREQUIRES (LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1643
+ inline constexpr bool operator ==(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1644
+ {
1645
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator== with path_view_component and a string literal, use .compare<>()" );
1646
+ return false ;
1647
+ }
1648
+ #if __cplusplus >= 202000L || _HAS_CXX20
1649
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view_component x, path_view_component y) noexcept
1650
+ {
1651
+ if (x.native_size () < y.native_size ())
1652
+ {
1653
+ return std::strong_ordering::less;
1654
+ }
1655
+ if (x.native_size () > y.native_size ())
1656
+ {
1657
+ return std::strong_ordering::greater;
1658
+ }
1659
+ if (x._passthrough < y._passthrough )
1660
+ {
1661
+ return std::strong_ordering::less;
1662
+ }
1663
+ if (x._passthrough > y._passthrough )
1664
+ {
1665
+ return std::strong_ordering::greater;
1666
+ }
1667
+ if (x._char < y._char )
1668
+ {
1669
+ return std::strong_ordering::less;
1670
+ }
1671
+ if (x._char > y._char )
1672
+ {
1673
+ return std::strong_ordering::greater;
1674
+ }
1675
+ if (x._wchar < y._wchar )
1676
+ {
1677
+ return std::strong_ordering::less;
1678
+ }
1679
+ if (x._wchar > y._wchar )
1680
+ {
1681
+ return std::strong_ordering::greater;
1682
+ }
1683
+ if (x._utf8 < y._utf8 )
1684
+ {
1685
+ return std::strong_ordering::less;
1686
+ }
1687
+ if (x._utf8 > y._utf8 )
1688
+ {
1689
+ return std::strong_ordering::greater;
1690
+ }
1691
+ if (x._utf16 < y._utf16 )
1692
+ {
1693
+ return std::strong_ordering::less;
1694
+ }
1695
+ if (x._utf16 > y._utf16 )
1696
+ {
1697
+ return std::strong_ordering::greater;
1698
+ }
1699
+ if (x.native_size () == 0 )
1700
+ {
1701
+ return std::strong_ordering::equal;
1702
+ }
1703
+ assert (x._bytestr != nullptr );
1704
+ assert (y._bytestr != nullptr );
1705
+ const auto bytes = (x._wchar || x._utf16 ) ? (x._length * 2 ) : x._length ;
1706
+ int comp = memcmp (x._bytestr , y._bytestr , bytes);
1707
+ if (comp == 0 )
1708
+ {
1709
+ return std::strong_ordering::equal;
1710
+ }
1711
+ else if (comp < 0 )
1712
+ {
1713
+ return std::strong_ordering::less;
1714
+ }
1715
+ return std::strong_ordering::greater;
1716
+ }
1717
+
1718
+ LLFIO_TEMPLATE (class CharT )
1719
+ LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1720
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator<=>(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1721
+ {
1722
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator<=> with path_view_component and a string literal, use .compare<>()" );
1723
+ return std::strong_ordering::equal;
1724
+ }
1725
+ LLFIO_TEMPLATE (class CharT )
1726
+ LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1727
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator<=>(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1728
+ {
1729
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator<=> with path_view_component and a string literal, use .compare<>()" );
1730
+ return std::strong_ordering::equal;
1731
+ }
1732
+
1733
+ #else
1638
1734
// ! \brief Compares **identity** inequality not disequivalence i.e. backing storage type must be different, or backing bytes must be different. Use `compare()`
1639
1735
// ! if you want something stronger.
1640
1736
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view_component x, path_view_component y) noexcept
@@ -1736,32 +1832,34 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view_component x, path_view
1736
1832
1737
1833
LLFIO_TEMPLATE (class CharT )
1738
1834
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1739
- inline constexpr bool operator = =(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1835
+ inline constexpr bool operator! =(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1740
1836
{
1741
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator= = with path_view_component and a string literal, use .compare<>()" );
1837
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator! = with path_view_component and a string literal, use .compare<>()" );
1742
1838
return false ;
1743
1839
}
1744
1840
LLFIO_TEMPLATE (class CharT )
1745
1841
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1746
- inline constexpr bool operator = =(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1842
+ inline constexpr bool operator! =(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1747
1843
{
1748
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator= = with path_view_component and a string literal, use .compare<>()" );
1844
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator! = with path_view_component and a string literal, use .compare<>()" );
1749
1845
return false ;
1750
1846
}
1751
1847
LLFIO_TEMPLATE (class CharT )
1752
1848
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1753
- inline constexpr bool operator != (path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1849
+ inline constexpr bool operator< (path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1754
1850
{
1755
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator!= with path_view_component and a string literal, use .compare<>()" );
1851
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator< with path_view_component and a string literal, use .compare<>()" );
1756
1852
return false ;
1757
1853
}
1758
1854
LLFIO_TEMPLATE (class CharT )
1759
1855
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1760
- inline constexpr bool operator != (const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1856
+ inline constexpr bool operator< (const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1761
1857
{
1762
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator!= with path_view_component and a string literal, use .compare<>()" );
1858
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator< with path_view_component and a string literal, use .compare<>()" );
1763
1859
return false ;
1764
1860
}
1861
+ #endif
1862
+
1765
1863
// ! \brief Hashes a `path_view_component`.
1766
1864
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view_component view) noexcept
1767
1865
{
@@ -1915,10 +2013,11 @@ class path_view : public path_view_component
1915
2013
{
1916
2014
friend class detail ::path_view_iterator;
1917
2015
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator ==(path_view x, path_view y) noexcept ;
2016
+ #if __cplusplus >= 202000L || _HAS_CXX20
2017
+ friend inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view x, path_view y) noexcept ;
2018
+ #else
1918
2019
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator !=(path_view x, path_view y) noexcept ;
1919
2020
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator <(path_view x, path_view y) noexcept ;
1920
- #if __cplusplus >= 202000L || _HAS_CXX20
1921
- friend inline LLFIO_PATH_VIEW_CONSTEXPR auto operator <=>(path_view x, path_view y) = default ;
1922
2021
#endif
1923
2022
friend inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view x) noexcept ;
1924
2023
@@ -2861,6 +2960,60 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator==(path_view x, path_view y) noexc
2861
2960
}
2862
2961
return true ;
2863
2962
}
2963
+ LLFIO_TEMPLATE (class CharT )
2964
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2965
+ inline constexpr bool operator ==(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2966
+ {
2967
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2968
+ return false ;
2969
+ }
2970
+ LLFIO_TEMPLATE (class CharT )
2971
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2972
+ inline constexpr bool operator ==(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
2973
+ {
2974
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2975
+ return false ;
2976
+ }
2977
+ #if __cplusplus >= 202000L || _HAS_CXX20
2978
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view x, path_view y) noexcept
2979
+ {
2980
+ auto it1 = x.begin (), it2 = y.begin ();
2981
+ for (; it1 != x.end () && it2 != y.end (); ++it1, ++it2)
2982
+ {
2983
+ if (*it1 < *it2)
2984
+ {
2985
+ return std::strong_ordering::less;
2986
+ }
2987
+ if (*it1 > *it2)
2988
+ {
2989
+ return std::strong_ordering::greater;
2990
+ }
2991
+ }
2992
+ if (it1 == x.end () && it2 != y.end ())
2993
+ {
2994
+ return std::strong_ordering::less;
2995
+ }
2996
+ if (it2 == x.end () && it1 != y.end ())
2997
+ {
2998
+ return std::strong_ordering::greater;
2999
+ }
3000
+ return std::strong_ordering::equal;
3001
+ }
3002
+ LLFIO_TEMPLATE (class CharT )
3003
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
3004
+ inline constexpr std::strong_ordering operator <=>(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
3005
+ {
3006
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator<=> with path_view and a string literal, use .compare<>()" );
3007
+ return std::strong_ordering::equal;
3008
+ }
3009
+ LLFIO_TEMPLATE (class CharT )
3010
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
3011
+ inline constexpr std::strong_ordering operator <=>(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
3012
+ {
3013
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator<=> with path_view and a string literal, use .compare<>()" );
3014
+ return std::strong_ordering::equal;
3015
+ }
3016
+ #else
2864
3017
// ! \brief Compares individual path view components for non-**identity** not disequivalence. Use `compare()` if you want something stronger.
2865
3018
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view x, path_view y) noexcept
2866
3019
{
@@ -2892,6 +3045,10 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view x, path_view y) noexce
2892
3045
{
2893
3046
return true ;
2894
3047
}
3048
+ if (*it2 < *it1)
3049
+ {
3050
+ return false ;
3051
+ }
2895
3052
}
2896
3053
if (it1 == x.end () && it2 != y.end ())
2897
3054
{
@@ -2901,20 +3058,6 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view x, path_view y) noexce
2901
3058
}
2902
3059
LLFIO_TEMPLATE (class CharT )
2903
3060
LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2904
- inline constexpr bool operator ==(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2905
- {
2906
- static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2907
- return false ;
2908
- }
2909
- LLFIO_TEMPLATE (class CharT )
2910
- LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2911
- inline constexpr bool operator ==(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
2912
- {
2913
- static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2914
- return false ;
2915
- }
2916
- LLFIO_TEMPLATE (class CharT )
2917
- LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2918
3061
inline constexpr bool operator !=(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2919
3062
{
2920
3063
static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator!= with path_view and a string literal, use .compare<>()" );
@@ -2927,6 +3070,7 @@ inline constexpr bool operator!=(const CharT * /*unused*/, path_view /*unused*/)
2927
3070
static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator!= with path_view and a string literal, use .compare<>()" );
2928
3071
return false ;
2929
3072
}
3073
+ #endif
2930
3074
// ! \brief Return the combined hash of individual path components
2931
3075
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view x) noexcept
2932
3076
{
0 commit comments