Skip to content

Commit b49d823

Browse files
committed
Convert static_assert in fly::detail::JsonIterator to use a concept
1 parent a02201d commit b49d823

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

fly/types/json/detail/json_iterator.hpp

+29-33
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ class JsonReverseIterator;
5353
* @author Timothy Flynn ([email protected])
5454
* @version May 17, 2020
5555
*/
56-
template <typename JsonType>
56+
template <fly::SameAs<Json> JsonType>
5757
class JsonIterator
5858
{
59-
static_assert(
60-
fly::SameAs<Json, JsonType>,
61-
"JsonIterator must only be declared for a Json type");
62-
6359
static constexpr bool is_const_iterator = std::is_const_v<JsonType>;
6460

6561
/**
@@ -487,7 +483,7 @@ class JsonIterator
487483
};
488484

489485
//==================================================================================================
490-
template <typename JsonType>
486+
template <fly::SameAs<Json> JsonType>
491487
JsonIterator<JsonType>::JsonIterator(pointer json, Position position) noexcept(false) : m_json(json)
492488
{
493489
auto visitor = [this, &position](auto &value) noexcept(JsonIterable<decltype(value)>)
@@ -517,7 +513,7 @@ JsonIterator<JsonType>::JsonIterator(pointer json, Position position) noexcept(f
517513
}
518514

519515
//==================================================================================================
520-
template <typename JsonType>
516+
template <fly::SameAs<Json> JsonType>
521517
JsonIterator<JsonType>::JsonIterator(const NonConstJsonIterator &iterator) noexcept :
522518
m_json(iterator.m_json)
523519
{
@@ -530,7 +526,7 @@ JsonIterator<JsonType>::JsonIterator(const NonConstJsonIterator &iterator) noexc
530526
}
531527

532528
//==================================================================================================
533-
template <typename JsonType>
529+
template <fly::SameAs<Json> JsonType>
534530
JsonIterator<JsonType> &
535531
JsonIterator<JsonType>::operator=(const NonConstJsonIterator &iterator) noexcept
536532
{
@@ -546,7 +542,7 @@ JsonIterator<JsonType>::operator=(const NonConstJsonIterator &iterator) noexcept
546542
}
547543

548544
//==================================================================================================
549-
template <typename JsonType>
545+
template <fly::SameAs<Json> JsonType>
550546
auto JsonIterator<JsonType>::operator*() const -> reference
551547
{
552548
validate_iterator();
@@ -569,7 +565,7 @@ auto JsonIterator<JsonType>::operator*() const -> reference
569565
}
570566

571567
//==================================================================================================
572-
template <typename JsonType>
568+
template <fly::SameAs<Json> JsonType>
573569
auto JsonIterator<JsonType>::operator->() const -> pointer
574570
{
575571
validate_iterator();
@@ -592,7 +588,7 @@ auto JsonIterator<JsonType>::operator->() const -> pointer
592588
}
593589

594590
//==================================================================================================
595-
template <typename JsonType>
591+
template <fly::SameAs<Json> JsonType>
596592
auto JsonIterator<JsonType>::operator[](difference_type offset) const -> reference
597593
{
598594
validate_iterator();
@@ -618,22 +614,22 @@ auto JsonIterator<JsonType>::operator[](difference_type offset) const -> referen
618614
}
619615

620616
//==================================================================================================
621-
template <typename JsonType>
617+
template <fly::SameAs<Json> JsonType>
622618
bool JsonIterator<JsonType>::operator==(const JsonIterator &iterator) const
623619
{
624620
validate_iterator(iterator);
625621
return m_iterator == iterator.m_iterator;
626622
}
627623

628624
//==================================================================================================
629-
template <typename JsonType>
625+
template <fly::SameAs<Json> JsonType>
630626
bool JsonIterator<JsonType>::operator!=(const JsonIterator &iterator) const
631627
{
632628
return !(*this == iterator);
633629
}
634630

635631
//==================================================================================================
636-
template <typename JsonType>
632+
template <fly::SameAs<Json> JsonType>
637633
bool JsonIterator<JsonType>::operator<(const JsonIterator &iterator) const
638634
{
639635
validate_iterator(iterator);
@@ -654,28 +650,28 @@ bool JsonIterator<JsonType>::operator<(const JsonIterator &iterator) const
654650
}
655651

656652
//==================================================================================================
657-
template <typename JsonType>
653+
template <fly::SameAs<Json> JsonType>
658654
bool JsonIterator<JsonType>::operator<=(const JsonIterator &iterator) const
659655
{
660656
return !(iterator < *this);
661657
}
662658

663659
//==================================================================================================
664-
template <typename JsonType>
660+
template <fly::SameAs<Json> JsonType>
665661
bool JsonIterator<JsonType>::operator>(const JsonIterator &iterator) const
666662
{
667663
return !(*this <= iterator);
668664
}
669665

670666
//==================================================================================================
671-
template <typename JsonType>
667+
template <fly::SameAs<Json> JsonType>
672668
bool JsonIterator<JsonType>::operator>=(const JsonIterator &iterator) const
673669
{
674670
return !(*this < iterator);
675671
}
676672

677673
//==================================================================================================
678-
template <typename JsonType>
674+
template <fly::SameAs<Json> JsonType>
679675
auto JsonIterator<JsonType>::operator++(int) -> JsonIterator
680676
{
681677
auto result = *this;
@@ -685,7 +681,7 @@ auto JsonIterator<JsonType>::operator++(int) -> JsonIterator
685681
}
686682

687683
//==================================================================================================
688-
template <typename JsonType>
684+
template <fly::SameAs<Json> JsonType>
689685
auto JsonIterator<JsonType>::operator++() -> JsonIterator &
690686
{
691687
validate_iterator();
@@ -702,7 +698,7 @@ auto JsonIterator<JsonType>::operator++() -> JsonIterator &
702698
}
703699

704700
//==================================================================================================
705-
template <typename JsonType>
701+
template <fly::SameAs<Json> JsonType>
706702
auto JsonIterator<JsonType>::operator--(int) -> JsonIterator
707703
{
708704
auto result = *this;
@@ -712,7 +708,7 @@ auto JsonIterator<JsonType>::operator--(int) -> JsonIterator
712708
}
713709

714710
//==================================================================================================
715-
template <typename JsonType>
711+
template <fly::SameAs<Json> JsonType>
716712
auto JsonIterator<JsonType>::operator--() -> JsonIterator &
717713
{
718714
validate_iterator();
@@ -729,7 +725,7 @@ auto JsonIterator<JsonType>::operator--() -> JsonIterator &
729725
}
730726

731727
//==================================================================================================
732-
template <typename JsonType>
728+
template <fly::SameAs<Json> JsonType>
733729
auto JsonIterator<JsonType>::operator+=(difference_type offset) -> JsonIterator &
734730
{
735731
validate_iterator();
@@ -752,14 +748,14 @@ auto JsonIterator<JsonType>::operator+=(difference_type offset) -> JsonIterator
752748
}
753749

754750
//==================================================================================================
755-
template <typename JsonType>
751+
template <fly::SameAs<Json> JsonType>
756752
auto JsonIterator<JsonType>::operator-=(difference_type offset) -> JsonIterator &
757753
{
758754
return *this += -offset;
759755
}
760756

761757
//==================================================================================================
762-
template <typename JsonType>
758+
template <fly::SameAs<Json> JsonType>
763759
auto JsonIterator<JsonType>::operator+(difference_type offset) const -> JsonIterator
764760
{
765761
auto result = *this;
@@ -769,7 +765,7 @@ auto JsonIterator<JsonType>::operator+(difference_type offset) const -> JsonIter
769765
}
770766

771767
//==================================================================================================
772-
template <typename JsonType>
768+
template <fly::SameAs<Json> JsonType>
773769
JsonIterator<JsonType> operator+(
774770
typename JsonIterator<JsonType>::difference_type offset,
775771
const JsonIterator<JsonType> &iterator)
@@ -781,7 +777,7 @@ JsonIterator<JsonType> operator+(
781777
}
782778

783779
//==================================================================================================
784-
template <typename JsonType>
780+
template <fly::SameAs<Json> JsonType>
785781
auto JsonIterator<JsonType>::operator-(difference_type offset) const -> JsonIterator
786782
{
787783
auto result = *this;
@@ -791,7 +787,7 @@ auto JsonIterator<JsonType>::operator-(difference_type offset) const -> JsonIter
791787
}
792788

793789
//==================================================================================================
794-
template <typename JsonType>
790+
template <fly::SameAs<Json> JsonType>
795791
auto JsonIterator<JsonType>::operator-(const JsonIterator &iterator) const -> difference_type
796792
{
797793
validate_iterator(iterator);
@@ -812,7 +808,7 @@ auto JsonIterator<JsonType>::operator-(const JsonIterator &iterator) const -> di
812808
}
813809

814810
//==================================================================================================
815-
template <typename JsonType>
811+
template <fly::SameAs<Json> JsonType>
816812
const typename json_object_type::key_type &JsonIterator<JsonType>::key() const
817813
{
818814
validate_iterator();
@@ -834,14 +830,14 @@ const typename json_object_type::key_type &JsonIterator<JsonType>::key() const
834830
}
835831

836832
//==================================================================================================
837-
template <typename JsonType>
833+
template <fly::SameAs<Json> JsonType>
838834
auto JsonIterator<JsonType>::value() const -> reference
839835
{
840836
return *(*this);
841837
}
842838

843839
//==================================================================================================
844-
template <typename JsonType>
840+
template <fly::SameAs<Json> JsonType>
845841
void JsonIterator<JsonType>::validate_iterator() const
846842
{
847843
if (m_json == nullptr)
@@ -851,7 +847,7 @@ void JsonIterator<JsonType>::validate_iterator() const
851847
}
852848

853849
//==================================================================================================
854-
template <typename JsonType>
850+
template <fly::SameAs<Json> JsonType>
855851
void JsonIterator<JsonType>::validate_iterator(const JsonIterator &iterator) const
856852
{
857853
validate_iterator();
@@ -864,7 +860,7 @@ void JsonIterator<JsonType>::validate_iterator(const JsonIterator &iterator) con
864860
}
865861

866862
//==================================================================================================
867-
template <typename JsonType>
863+
template <fly::SameAs<Json> JsonType>
868864
template <typename T>
869865
void JsonIterator<JsonType>::validate_offset(const T &it, difference_type offset) const
870866

@@ -889,7 +885,7 @@ void JsonIterator<JsonType>::validate_offset(const T &it, difference_type offset
889885
}
890886

891887
//==================================================================================================
892-
template <typename JsonType>
888+
template <fly::SameAs<Json> JsonType>
893889
template <typename T>
894890
void JsonIterator<JsonType>::validate_dereference(const T &it) const
895891
{

0 commit comments

Comments
 (0)