@@ -90,7 +90,7 @@ struct Square {
9090 double length{0.0 };
9191};
9292
93- auto MotivationalExample = test([] {
93+ const auto MotivationalExample = test([] {
9494 std::vector<some<Drawable>> someDrawables;
9595
9696 someDrawables.emplace_back (Circle{1.0 });
@@ -145,7 +145,7 @@ constexpr auto WithSummary = trait{
145145
146146// ... you can use a trait
147147
148- decltype ( auto ) operator <<(std::ostream& stream, is<Drawable> auto const & drawable) {
148+ auto operator <<(std::ostream& stream, is<Drawable> auto const & drawable) -> decltype ( auto ) {
149149 drawable.draw (stream);
150150 return stream;
151151}
@@ -379,7 +379,7 @@ auto run(is<Action> auto& action) {
379379// let's use it
380380
381381struct SimpleAction {
382- bool run () {
382+ auto run () -> bool {
383383 printSourceLocation ();
384384 return true ;
385385 }
@@ -393,7 +393,7 @@ auto RunSimpleAction = test([] {
393393// traits allow you to implement behavior in a non-intrusive manner
394394
395395struct ForeignAction {
396- enum class Status { Failed, Ok };
396+ enum class Status : std:: uint8_t { Failed, Ok };
397397
398398 auto execute () {
399399 if (not ready) return Status::Failed;
@@ -539,13 +539,13 @@ auto FooBar = test([] {
539539
540540 overloadedValueCategory.bar (std::as_const (c));
541541 overloadedValueCategory.bar (c);
542- overloadedValueCategory.bar (std::move (c) );
542+ overloadedValueCategory.bar (c );
543543
544544 int i = 0 ;
545545
546546 overloadedValueCategory.bar (std::as_const (i));
547547 overloadedValueCategory.bar (i);
548- overloadedValueCategory.bar (std::move (i) );
548+ overloadedValueCategory.bar (i );
549549
550550 some<OverloadedArity> overloadedArity = Foo{};
551551
@@ -577,10 +577,10 @@ template <typename T>
577577class EmbeddedList {
578578 public:
579579 using iterator = const T*;
580- iterator begin () const ;
581- iterator end () const ;
582- bool empty () const ;
583- T& front ();
580+ [[nodiscard]] auto begin () const -> iterator ;
581+ [[nodiscard]] auto end () const -> iterator ;
582+ [[nodiscard]] auto empty () const -> bool ;
583+ auto front () -> T& ;
584584 void push_back (T&);
585585
586586 /* ... */
@@ -592,9 +592,9 @@ class GeoConstraintIF : public EmbeddedListNode<GeoConstraintIF> {
592592 virtual ~GeoConstraintIF () = default ;
593593
594594 void setBreaking (bool breaking) { mBreaking = breaking; }
595- bool isBreaking () const { return mBreaking ; }
595+ [[nodiscard]] auto isBreaking () const -> bool { return mBreaking ; }
596596
597- virtual bool checkPoint (const Vector3i& point) const = 0;
597+ [[nodiscard]] virtual auto checkPoint (const Vector3i& point) const -> bool = 0;
598598
599599 private:
600600 bool mBreaking {false };
@@ -608,7 +608,7 @@ class RegionGrowerIF {
608608 }
609609 }
610610
611- bool addGeoConstraint (GeoConstraintIF* constraint) {
611+ auto addGeoConstraint (GeoConstraintIF* constraint) -> bool {
612612 if (! constraint) {
613613 return false ;
614614 }
@@ -617,13 +617,12 @@ class RegionGrowerIF {
617617 return true ;
618618 }
619619
620- private:
621620 // don't know how to copy the constraints ...
622621 RegionGrowerIF (RegionGrowerIF const & other) = delete ;
623- RegionGrowerIF& operator =(RegionGrowerIF const & other) = delete ;
622+ auto operator =(RegionGrowerIF const & other) -> RegionGrowerIF& = delete ;
624623
625624 protected:
626- bool checkGeoConstraints (Vector3i const & point) {
625+ auto checkGeoConstraints (Vector3i const & point) -> bool {
627626 for (const auto & constraint : mGeoConstraints )
628627 if (not constraint.checkPoint (point)) return false ;
629628
@@ -653,7 +652,7 @@ class RegionGrower {
653652 }
654653
655654 protected:
656- bool checkGeoConstraints (Vector3i const & point) {
655+ auto checkGeoConstraints (Vector3i const & point) -> bool {
657656 return std::ranges::all_of (mGeoConstraints ,
658657 [&](auto const & constraint) { return constraint.check (point); });
659658 }
@@ -672,7 +671,7 @@ class RegionGrower {
672671
673672struct Breakable {
674673 constexpr void setBreaking (bool breaking) { mBreaking = breaking; }
675- constexpr bool isBreaking () const { return mBreaking ; }
674+ [[nodiscard]] constexpr auto isBreaking () const -> bool { return mBreaking ; }
676675
677676 private:
678677 bool mBreaking {false };
@@ -688,14 +687,14 @@ static_assert(sizeof(Breakable) == 112);
688687
689688template <Vector3i Low>
690689struct GreaterOrEqual : Breakable {
691- bool check (const Vector3i& point) const {
690+ [[nodiscard]] auto check (const Vector3i& point) const -> bool {
692691 return point.x >= Low.x and point.y >= Low.y and point.z >= Low.z ;
693692 }
694693};
695694
696695template <Vector3i High>
697696struct LessOrEqual : Breakable {
698- bool check (const Vector3i& point) const {
697+ [[nodiscard]] auto check (const Vector3i& point) const -> bool {
699698 return point.x <= High.x and point.y <= High.y and point.z <= High.z ;
700699 }
701700};
@@ -713,7 +712,7 @@ class TestableRegionGrower : public RegionGrower {
713712 }
714713
715714 public:
716- static bool test () {
715+ static auto test () -> bool {
717716 auto regionGrower = makeRegionGrower ();
718717 return regionGrower.checkGeoConstraints (Vector3i{0 , 1 , 2 });
719718 }
@@ -731,7 +730,7 @@ namespace with_stronger_coupling {
731730
732731struct GeoConstraintIF {
733732 constexpr void setBreaking (bool breaking) { mBreaking = breaking; }
734- constexpr bool isBreaking () const { return mBreaking ; }
733+ [[nodiscard]] constexpr auto isBreaking () const -> bool { return mBreaking ; }
735734
736735 private:
737736 bool mBreaking {false };
@@ -750,7 +749,7 @@ class RegionGrower {
750749 }
751750
752751 protected:
753- bool checkGeoConstraints (Vector3i const & point) {
752+ auto checkGeoConstraints (Vector3i const & point) -> bool {
754753 return std::ranges::all_of (mGeoConstraints ,
755754 [&](auto const & constraint) { return constraint.check (point); });
756755 }
@@ -765,14 +764,14 @@ class RegionGrower {
765764
766765template <Vector3i Low>
767766struct GreaterOrEqual : GeoConstraintIF {
768- bool check (const Vector3i& point) const {
767+ [[nodiscard]] auto check (const Vector3i& point) const -> bool {
769768 return point.x >= Low.x and point.y >= Low.y and point.z >= Low.z ;
770769 }
771770};
772771
773772template <Vector3i High>
774773struct LessOrEqual : GeoConstraintIF {
775- bool check (const Vector3i& point) const {
774+ [[nodiscard]] auto check (const Vector3i& point) const -> bool {
776775 return point.x <= High.x and point.y <= High.y and point.z <= High.z ;
777776 }
778777};
@@ -841,7 +840,7 @@ auto PrintName = test([] {
841840#pragma clang diagnostic pop
842841#endif
843842
844- int main () {
843+ auto main () -> int {
845844 using namespace trait_examples ;
846845
847846 test::run_all ();
0 commit comments