Skip to content

Commit

Permalink
#125 Partial concept refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
xthebat committed Jan 13, 2024
1 parent 422c95c commit 10eeea5
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 28 deletions.
56 changes: 56 additions & 0 deletions Source/Cloud9/Tools/Concepts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2023 Alexei Gladkikh
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#pragma once

/**
* std abstraction because UE4 has self APIs to avoid mixin std and UE4 APIs
*/
namespace Concepts
{
template <typename SelfType>
concept incrementable = requires(SelfType Self)
{
++Self;
};

template <typename SelfType, typename OtherType>
concept plusassingable =
incrementable<SelfType>
&& requires(SelfType Self, OtherType Other)
{
Self += Other;
};

template <typename SelfType, typename BoundType>
concept dereferencable = requires(SelfType Self)
{
{ *Self } -> std::convertible_to<BoundType>;
};

template <typename SelfType, typename BoundType>
concept convertiable = requires(SelfType Self)
{
{ Self } -> std::convertible_to<BoundType>;
};
}
4 changes: 2 additions & 2 deletions Source/Cloud9/Tools/Extensions/FString.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#pragma once

#include "Cloud9/Tools/Macro/Operator.h"
#include "Cloud9/Tools/Macro/Template.h"
#include "Cloud9/Tools/Concepts.h"

namespace EFString
{
struct ToCStr
{
template <typename SelfType, sametype(SelfType, FString)>
template <typename SelfType> requires Concepts::convertiable<SelfType, FString>
FORCEINLINE const TCHAR* operator()(SelfType&& Self) const { return *Self; }

OPERATOR_BODY(ToCStr)
Expand Down
4 changes: 2 additions & 2 deletions Source/Cloud9/Tools/Extensions/FVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#pragma once

#include "Cloud9/Tools/Macro/Operator.h"
#include "Cloud9/Tools/Macro/Template.h"
#include "Cloud9/Tools/Concepts.h"

namespace EFVector
{
struct Normalize
{
template <typename SelfType, sametype(SelfType, FVector)>
template <typename SelfType> requires Concepts::convertiable<SelfType, FVector>
FORCEINLINE FVector operator()(SelfType&& Self) const
{
FVector Normalized = Self;
Expand Down
26 changes: 2 additions & 24 deletions Source/Cloud9/Tools/Extensions/TContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,13 @@

#pragma once

#include "Cloud9/Tools/Concepts.h"
#include "Cloud9/Tools/Macro/Common.h"
#include "Cloud9/Tools/Macro/Logging.h"
#include "Cloud9/Tools/Macro/Operator.h"
#include "Cloud9/Tools/Containers/Sequence.h"
#include "Cloud9/Tools/Extensions/TOptional.h"

namespace Concepts
{
template <typename IteratorType>
concept incrementable = requires(IteratorType Iterator)
{
++Iterator;
};

template <typename IteratorType, typename SizeType>
concept moveable =
incrementable<IteratorType>
&& requires(IteratorType Iterator, SizeType Distance)
{
Iterator += Distance;
};

template <typename IteratorType, typename ValueType>
concept dereferencable = requires(IteratorType Iterator)
{
{ *Iterator } -> std::convertible_to<ValueType>;
};
}

namespace ETIterator
{
template <typename SizeType>
Expand All @@ -62,7 +40,7 @@ namespace ETIterator
return Self;
}

constexpr auto operator()(Concepts::moveable<SizeType> auto Self) const
constexpr auto operator()(Concepts::plusassingable<SizeType> auto Self) const
{
Self += Distance;
return Self;
Expand Down

0 comments on commit 10eeea5

Please sign in to comment.