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);
@@ -1596,6 +1591,7 @@ class LLFIO_DECL path_view_component
1596
1591
};
1597
1592
static_assert (std::is_trivially_copyable<path_view_component>::value, " path_view_component is not trivially copyable!" );
1598
1593
static_assert (sizeof (path_view_component) == 3 * sizeof(void *), "path_view_component is not three pointers in size!");
1594
+
1599
1595
// ! \brief Compares **identity** equality not equivalence i.e. backing storage type must be identical, and backing bytes must be identical. Use `compare()` if
1600
1596
// ! you want something stronger.
1601
1597
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator ==(path_view_component x, path_view_component y) noexcept
@@ -1633,6 +1629,106 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator==(path_view_component x, path_vie
1633
1629
const auto bytes = (x._wchar || x._utf16 ) ? (x._length * 2 ) : x._length ;
1634
1630
return 0 == memcmp (x._bytestr , y._bytestr , bytes);
1635
1631
}
1632
+ LLFIO_TEMPLATE (class CharT )
1633
+ LLFIO_TREQUIRES (LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1634
+ inline constexpr bool operator ==(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1635
+ {
1636
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator== with path_view_component and a string literal, use .compare<>()" );
1637
+ return false ;
1638
+ }
1639
+ LLFIO_TEMPLATE (class CharT )
1640
+ LLFIO_TREQUIRES (LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1641
+ inline constexpr bool operator ==(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1642
+ {
1643
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator== with path_view_component and a string literal, use .compare<>()" );
1644
+ return false ;
1645
+ }
1646
+ #if __cplusplus >= 202000L || _HAS_CXX20
1647
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view_component x, path_view_component y) noexcept
1648
+ {
1649
+ if (x.native_size () < y.native_size ())
1650
+ {
1651
+ return std::strong_ordering::less;
1652
+ }
1653
+ if (x.native_size () > y.native_size ())
1654
+ {
1655
+ return std::strong_ordering::greater;
1656
+ }
1657
+ if (x._passthrough < y._passthrough )
1658
+ {
1659
+ return std::strong_ordering::less;
1660
+ }
1661
+ if (x._passthrough > y._passthrough )
1662
+ {
1663
+ return std::strong_ordering::greater;
1664
+ }
1665
+ if (x._char < y._char )
1666
+ {
1667
+ return std::strong_ordering::less;
1668
+ }
1669
+ if (x._char > y._char )
1670
+ {
1671
+ return std::strong_ordering::greater;
1672
+ }
1673
+ if (x._wchar < y._wchar )
1674
+ {
1675
+ return std::strong_ordering::less;
1676
+ }
1677
+ if (x._wchar > y._wchar )
1678
+ {
1679
+ return std::strong_ordering::greater;
1680
+ }
1681
+ if (x._utf8 < y._utf8 )
1682
+ {
1683
+ return std::strong_ordering::less;
1684
+ }
1685
+ if (x._utf8 > y._utf8 )
1686
+ {
1687
+ return std::strong_ordering::greater;
1688
+ }
1689
+ if (x._utf16 < y._utf16 )
1690
+ {
1691
+ return std::strong_ordering::less;
1692
+ }
1693
+ if (x._utf16 > y._utf16 )
1694
+ {
1695
+ return std::strong_ordering::greater;
1696
+ }
1697
+ if (x.native_size () == 0 )
1698
+ {
1699
+ return std::strong_ordering::equal;
1700
+ }
1701
+ assert (x._bytestr != nullptr );
1702
+ assert (y._bytestr != nullptr );
1703
+ const auto bytes = (x._wchar || x._utf16 ) ? (x._length * 2 ) : x._length ;
1704
+ int comp = memcmp (x._bytestr , y._bytestr , bytes);
1705
+ if (comp == 0 )
1706
+ {
1707
+ return std::strong_ordering::equal;
1708
+ }
1709
+ else if (comp < 0 )
1710
+ {
1711
+ return std::strong_ordering::less;
1712
+ }
1713
+ return std::strong_ordering::greater;
1714
+ }
1715
+
1716
+ LLFIO_TEMPLATE (class CharT )
1717
+ LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1718
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator<=>(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1719
+ {
1720
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator<=> with path_view_component and a string literal, use .compare<>()" );
1721
+ return std::strong_ordering::equal;
1722
+ }
1723
+ LLFIO_TEMPLATE (class CharT )
1724
+ LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1725
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator<=>(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1726
+ {
1727
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator<=> with path_view_component and a string literal, use .compare<>()" );
1728
+ return std::strong_ordering::equal;
1729
+ }
1730
+
1731
+ #else
1636
1732
// ! \brief Compares **identity** inequality not disequivalence i.e. backing storage type must be different, or backing bytes must be different. Use `compare()`
1637
1733
// ! if you want something stronger.
1638
1734
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view_component x, path_view_component y) noexcept
@@ -1734,32 +1830,34 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view_component x, path_view
1734
1830
1735
1831
LLFIO_TEMPLATE (class CharT )
1736
1832
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1737
- inline constexpr bool operator = =(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1833
+ inline constexpr bool operator! =(path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1738
1834
{
1739
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator= = with path_view_component and a string literal, use .compare<>()" );
1835
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator! = with path_view_component and a string literal, use .compare<>()" );
1740
1836
return false ;
1741
1837
}
1742
1838
LLFIO_TEMPLATE (class CharT )
1743
1839
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1744
- inline constexpr bool operator = =(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1840
+ inline constexpr bool operator! =(const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1745
1841
{
1746
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator= = with path_view_component and a string literal, use .compare<>()" );
1842
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator! = with path_view_component and a string literal, use .compare<>()" );
1747
1843
return false ;
1748
1844
}
1749
1845
LLFIO_TEMPLATE (class CharT )
1750
1846
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1751
- inline constexpr bool operator != (path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1847
+ inline constexpr bool operator< (path_view_component /* unused*/ , const CharT * /* unused*/ ) noexcept
1752
1848
{
1753
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator!= with path_view_component and a string literal, use .compare<>()" );
1849
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator< with path_view_component and a string literal, use .compare<>()" );
1754
1850
return false ;
1755
1851
}
1756
1852
LLFIO_TEMPLATE (class CharT )
1757
1853
LLFIO_TREQUIRES(LLFIO_TPRED(path_view_component::is_source_acceptable<CharT>))
1758
- inline constexpr bool operator != (const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1854
+ inline constexpr bool operator< (const CharT * /* unused*/ , path_view_component /* unused*/ ) noexcept
1759
1855
{
1760
- static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator!= with path_view_component and a string literal, use .compare<>()" );
1856
+ static_assert (!path_view_component::is_source_acceptable<CharT>, " Do not use operator< with path_view_component and a string literal, use .compare<>()" );
1761
1857
return false ;
1762
1858
}
1859
+ #endif
1860
+
1763
1861
// ! \brief Hashes a `path_view_component`.
1764
1862
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view_component view) noexcept
1765
1863
{
@@ -1913,10 +2011,11 @@ class path_view : public path_view_component
1913
2011
{
1914
2012
friend class detail ::path_view_iterator;
1915
2013
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator ==(path_view x, path_view y) noexcept ;
2014
+ #if __cplusplus >= 202000L || _HAS_CXX20
2015
+ friend inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view x, path_view y) noexcept ;
2016
+ #else
1916
2017
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator !=(path_view x, path_view y) noexcept ;
1917
2018
friend inline LLFIO_PATH_VIEW_CONSTEXPR bool LLFIO_V2_NAMESPACE::operator <(path_view x, path_view y) noexcept ;
1918
- #if __cplusplus >= 202000L || _HAS_CXX20
1919
- friend inline LLFIO_PATH_VIEW_CONSTEXPR auto operator <=>(path_view x, path_view y) = default ;
1920
2019
#endif
1921
2020
friend inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view x) noexcept ;
1922
2021
@@ -2859,6 +2958,60 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator==(path_view x, path_view y) noexc
2859
2958
}
2860
2959
return true ;
2861
2960
}
2961
+ LLFIO_TEMPLATE (class CharT )
2962
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2963
+ inline constexpr bool operator ==(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2964
+ {
2965
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2966
+ return false ;
2967
+ }
2968
+ LLFIO_TEMPLATE (class CharT )
2969
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2970
+ inline constexpr bool operator ==(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
2971
+ {
2972
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2973
+ return false ;
2974
+ }
2975
+ #if __cplusplus >= 202000L || _HAS_CXX20
2976
+ inline LLFIO_PATH_VIEW_CONSTEXPR std::strong_ordering operator <=>(path_view x, path_view y) noexcept
2977
+ {
2978
+ auto it1 = x.begin (), it2 = y.begin ();
2979
+ for (; it1 != x.end () && it2 != y.end (); ++it1, ++it2)
2980
+ {
2981
+ if (*it1 < *it2)
2982
+ {
2983
+ return std::strong_ordering::less;
2984
+ }
2985
+ if (*it1 > *it2)
2986
+ {
2987
+ return std::strong_ordering::greater;
2988
+ }
2989
+ }
2990
+ if (it1 == x.end () && it2 != y.end ())
2991
+ {
2992
+ return std::strong_ordering::less;
2993
+ }
2994
+ if (it2 == x.end () && it1 != y.end ())
2995
+ {
2996
+ return std::strong_ordering::greater;
2997
+ }
2998
+ return std::strong_ordering::equal;
2999
+ }
3000
+ LLFIO_TEMPLATE (class CharT )
3001
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
3002
+ inline constexpr std::strong_ordering operator <=>(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
3003
+ {
3004
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator<=> with path_view and a string literal, use .compare<>()" );
3005
+ return std::strong_ordering::equal;
3006
+ }
3007
+ LLFIO_TEMPLATE (class CharT )
3008
+ LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
3009
+ inline constexpr std::strong_ordering operator <=>(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
3010
+ {
3011
+ static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator<=> with path_view and a string literal, use .compare<>()" );
3012
+ return std::strong_ordering::equal;
3013
+ }
3014
+ #else
2862
3015
// ! \brief Compares individual path view components for non-**identity** not disequivalence. Use `compare()` if you want something stronger.
2863
3016
inline LLFIO_PATH_VIEW_CONSTEXPR bool operator !=(path_view x, path_view y) noexcept
2864
3017
{
@@ -2890,6 +3043,10 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view x, path_view y) noexce
2890
3043
{
2891
3044
return true ;
2892
3045
}
3046
+ if (*it2 < *it1)
3047
+ {
3048
+ return false ;
3049
+ }
2893
3050
}
2894
3051
if (it1 == x.end () && it2 != y.end ())
2895
3052
{
@@ -2899,20 +3056,6 @@ inline LLFIO_PATH_VIEW_CONSTEXPR bool operator<(path_view x, path_view y) noexce
2899
3056
}
2900
3057
LLFIO_TEMPLATE (class CharT )
2901
3058
LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2902
- inline constexpr bool operator ==(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2903
- {
2904
- static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2905
- return false ;
2906
- }
2907
- LLFIO_TEMPLATE (class CharT )
2908
- LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2909
- inline constexpr bool operator ==(const CharT * /* unused*/ , path_view /* unused*/ ) noexcept
2910
- {
2911
- static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator== with path_view and a string literal, use .compare<>()" );
2912
- return false ;
2913
- }
2914
- LLFIO_TEMPLATE (class CharT )
2915
- LLFIO_TREQUIRES (LLFIO_TPRED (path_view::is_source_acceptable<CharT>))
2916
3059
inline constexpr bool operator !=(path_view /* unused*/ , const CharT * /* unused*/ ) noexcept
2917
3060
{
2918
3061
static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator!= with path_view and a string literal, use .compare<>()" );
@@ -2925,6 +3068,7 @@ inline constexpr bool operator!=(const CharT * /*unused*/, path_view /*unused*/)
2925
3068
static_assert (!path_view::is_source_acceptable<CharT>, " Do not use operator!= with path_view and a string literal, use .compare<>()" );
2926
3069
return false ;
2927
3070
}
3071
+ #endif
2928
3072
// ! \brief Return the combined hash of individual path components
2929
3073
inline LLFIO_PATH_VIEW_CONSTEXPR size_t hash_value (path_view x) noexcept
2930
3074
{
0 commit comments