Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sweep: Add CLinkAddress concept #113

Closed
1 task done
FreePhoenix888 opened this issue Sep 20, 2023 · 2 comments · Fixed by #116
Closed
1 task done

Sweep: Add CLinkAddress concept #113

FreePhoenix888 opened this issue Sep 20, 2023 · 2 comments · Fixed by #116
Labels
sweep Sweep your software chores

Comments

@FreePhoenix888
Copy link
Member

FreePhoenix888 commented Sep 20, 2023

Sweep: Add CLinkAddress concept to cpp/Platform.Interfaces/. CLinkAddress must check that argument is integral and unsigned

Checklist
  • cpp/Platform.Interfaces/CLinkAddress.h ✅ Commit 0e26908
• Include the `` and `` libraries at the beginning of the file. • Define the `Platform::Interfaces` namespace. • Inside the namespace, define the `CLinkAddress` concept that takes a single template argument `T`. • The concept should check if `T` is both integral and unsigned using `std::is_integral` and `std::is_unsigned` respectively.
@linksplatform-sweepai linksplatform-sweepai bot added the sweep Sweep your software chores label Sep 20, 2023
@linksplatform-sweepai
Copy link
Contributor

linksplatform-sweepai bot commented Sep 20, 2023

Here's the PR! #116.

💎 Sweep Pro: I used GPT-4 to create this ticket. You have unlimited GPT-4 tickets.

Actions (click)

  • ↻ Restart Sweep

Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description.

#pragma once
#include <concepts>
#include <ranges>
#include <tuple>
#include <type_traits>
#include "CEnumerable.h"
namespace Platform::Interfaces {
namespace Internal {
template <typename TRawSelf, typename... TItems>
consteval bool CSetHelpFunction() {
using Self = std::remove_const_t<TRawSelf>;
if constexpr (sizeof...(TItems) == 1) {
return requires(Self self, std::tuple<TItems...> items, decltype(std::get<0>(items)) item) {
{ self.find(item) } -> std::same_as<std::ranges::iterator_t<Self>>;
{self.insert(item)};
{self.erase(item)};
{ self.contains(item) } -> std::same_as<bool>;
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
if constexpr (sizeof...(TItems) == 0) {
return requires(Self self, typename Enumerable<Self>::Item generic_item) {
{ self.find(generic_item) } -> std::same_as<std::ranges::iterator_t<Self>>;
{self.insert(generic_item)};
{self.erase(generic_item)};
{ self.contains(generic_item) } -> std::same_as<bool>;
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
return false;
}
} // namespace Internal
template <typename TSelf, typename... TItems>
concept CSet = CEnumerable<TSelf> && Internal::CSetHelpFunction<TSelf, TItems...>();
template <CSet TSelf>
struct Set : Enumerable<TSelf> {};

#pragma once
#include <concepts>
#include <iterator>
#include <ranges>
#include <tuple>
#include <type_traits>
#include <utility>
#include "CEnumerable.h"
namespace Platform::Interfaces {
namespace Internal {
template <typename TRawSelf, typename... TArgs>
consteval bool CDictionaryHelpFunction() {
using Self = std::remove_const_t<TRawSelf>;
using GenericKey = std::remove_reference_t<decltype(std::get<0>(std::declval<typename Enumerable<Self>::Item>()))>;
using GenericValue = std::remove_reference_t<decltype(std::get<1>(std::declval<typename Enumerable<Self>::Item>()))>;
if constexpr (sizeof...(TArgs) == 0) {
return requires(Self self, GenericKey generic_key, GenericValue generic_value) {
{ self[generic_key] } -> std::same_as<GenericValue&>;
{ self.find(generic_key) } -> std::forward_iterator;
{ self.contains(generic_key) } -> std::same_as<bool>;
{self.insert({generic_key, generic_value})};
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
if constexpr (sizeof...(TArgs) == 1) {
return requires(Self self, std::tuple<TArgs...> args,
decltype(std::get<0>(args)) key, decltype(std::declval<Enumerable<Self>::Item>().second) generic_value) {
{ self[key] } -> std::same_as<GenericValue&>;
{ self.find(key) } -> std::forward_iterator;
{ self.contains(key) } -> std::same_as<bool>;
{self.insert({key, generic_value})};
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
if constexpr (sizeof...(TArgs) == 2) {
return requires(Self self, std::tuple<TArgs...> args,
decltype(std::get<0>(args)) key, decltype(std::get<1>(args)) value) {
{ self[key] } -> std::same_as<GenericValue&>;
{ self.find(key) } -> std::forward_iterator;
{ self.contains(key) } -> std::same_as<bool>;
{self.insert({key, value})};
{ self.empty() } -> std::same_as<bool>;
{ self.size() } -> std::integral;
{self.clear()};
requires std::ranges::forward_range<Self>;
};
}
return false;
}
} // namespace Internal
template <typename TSelf, typename... TArgs>
concept CDictionary = CEnumerable<TSelf> && Internal::CDictionaryHelpFunction<TSelf, TArgs...>();
template <CDictionary TSelf>
struct Dictionary : Enumerable<TSelf> {
using base = Enumerable<TSelf>;
using Key = decltype(std::get<0>(std::declval<base::Item>()));
using Value = decltype(std::get<1>(std::declval<base::Item>()));
};

https://github.com/linksplatform/Interfaces/blob/825997338e0852ecada7cfcfc58da7f7d918e80c/cpp/Platform.Interfaces/ICounter[TResult].h#L1-L12

#pragma once
namespace Platform::Interfaces {
template <typename...>
struct IFactory;
template <typename TProduct>
struct IFactory<TProduct> {
virtual TProduct Create() = 0;
virtual ~IFactory() = default;
};

#pragma once
namespace Platform::Interfaces {
template <typename...>
struct ICriterionMatcher;
template <typename TArgument>
struct ICriterionMatcher<TArgument> {
virtual bool IsMatched(TArgument argument) = 0;
virtual ~ICriterionMatcher() = default;
};


Step 2: ⌨️ Coding

  • cpp/Platform.Interfaces/CLinkAddress.h ✅ Commit 0e26908
• Include the `` and `` libraries at the beginning of the file. • Define the `Platform::Interfaces` namespace. • Inside the namespace, define the `CLinkAddress` concept that takes a single template argument `T`. • The concept should check if `T` is both integral and unsigned using `std::is_integral` and `std::is_unsigned` respectively.

Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add-clinkaddress-concept.

.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.
Join Our Discord

This was referenced Sep 20, 2023
@FreePhoenix888
Copy link
Member Author

Sweep: you should write C++ concept, not struct!
Here is an example of C++ concept:

#pragma once

#include <concepts>

namespace Platform::Interfaces {
  template <typename TSelf, typename TValue, typename... TArgument>
  concept CSetter = sizeof...(TArgument) <= 1 && requires(TSelf self, TArgument... argument, TValue value) {
    { self.Set(argument..., value) } -> std::same_as<void>;
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Sweep your software chores
Projects
None yet
1 participant