Skip to content

Commit

Permalink
Merge pull request #76 from linksplatform/cppwrite(norwend_like)
Browse files Browse the repository at this point in the history
[C++] 0.1.3
  • Loading branch information
uselessgoddess authored Jul 2, 2021
2 parents 181e070 + 6f4fec5 commit 6c1408e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
9 changes: 7 additions & 2 deletions cpp/Platform.Interfaces/IArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ namespace Platform::Interfaces
template<typename Self, typename... Items>
consteval bool IArrayHelpFunction()
{
constexpr bool member_indexator = requires(Self self, std::size_t index)
{
{ self[index] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
};

if constexpr (sizeof...(Items) == 1)
{
using SelfItem = typename Enumerable<Self>::Item;
using RequiredItem = std::remove_reference_t<decltype(std::get<0>(std::declval<std::tuple<Items...>>()))>;

return std::ranges::random_access_range<Self> && std::same_as<SelfItem, RequiredItem>;
return member_indexator && std::ranges::random_access_range<Self> && std::same_as<SelfItem, RequiredItem>;
}
if constexpr (sizeof...(Items) == 0)
{
return std::ranges::random_access_range<Self>;
return member_indexator && std::ranges::random_access_range<Self>;
}

return false;
Expand Down
17 changes: 11 additions & 6 deletions cpp/Platform.Interfaces/IDictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ namespace Platform::Interfaces
{
namespace Internal
{
template<typename Self, typename... Args>
template<typename RawSelf, typename... Args>
consteval bool IDictionaryHelpFunction()
{
using Self = std::remove_const_t<RawSelf>;

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...(Args) == 0)
{
return requires
(
Self self,
decltype(std::declval<Enumerable<Self>::Item>().first) generic_key,
decltype(std::declval<Enumerable<Self>::Item>().second) generic_value
GenericKey generic_key,
GenericValue generic_value
)
{
{ self[generic_key] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
{ 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}) };
Expand All @@ -36,7 +41,7 @@ namespace Platform::Interfaces
decltype(std::declval<Enumerable<Self>::Item>().second) generic_value
)
{
{ self[key] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
{ self[key] } -> std::same_as<GenericValue&>;
{ self.find(key) } -> std::forward_iterator;
{ self.contains(key) } -> std::same_as<bool>;
{ self.insert({key, generic_value}) };
Expand All @@ -58,7 +63,7 @@ namespace Platform::Interfaces
decltype(std::get<1>(args)) value
)
{
{ self[key] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
{ self[key] } -> std::same_as<GenericValue&>;
{ self.find(key) } -> std::forward_iterator;
{ self.contains(key) } -> std::same_as<bool>;
{ self.insert({key, value}) };
Expand Down
6 changes: 3 additions & 3 deletions cpp/Platform.Interfaces/IList.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace Platform::Interfaces
{
namespace Internal
{
template<typename Self, typename... Item>
template<typename RawSelf, typename... Item>
consteval bool IListHelpFunction()
{
using Self = std::remove_const_t<RawSelf>;

if constexpr (sizeof...(Item) == 1)
{
return requires
Expand All @@ -16,7 +18,6 @@ namespace Platform::Interfaces
std::ranges::iterator_t<const Self> const_iterator
)
{
{ self[index] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
{ self.push_back(item) };
{ self.insert(const_iterator, item) };
{ self.erase(const_iterator) };
Expand All @@ -34,7 +35,6 @@ namespace Platform::Interfaces
typename Enumerable<const Self>::Iter const_iterator
)
{
{ self[index] } -> std::same_as<typename Enumerable<Self>::ItemReference>;
{ self.push_back(generic_item) };
{ self.insert(const_iterator, generic_item) };
{ self.erase(const_iterator) };
Expand Down
4 changes: 3 additions & 1 deletion cpp/Platform.Interfaces/ISet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace Platform::Interfaces
{
namespace Internal
{
template<typename Self, typename... Items>
template<typename RawSelf, typename... Items>
consteval bool ISetHelpFunction()
{
using Self = std::remove_const_t<RawSelf>;

if constexpr (sizeof...(Items) == 1)
{
return requires
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
<summary>LinksPlatform's Platform.Interfaces is a Template Library what contains common concepts templates.</summary>
<description>LinksPlatform's Platform.Interfaces is a Template Library what contains set of C++ concepts templates. Use Platform.Interfaces.h file to include the library.</description>
<releaseNotes>
Fixed compile-error bug => (concepts without Item type tried get first type from Items... set)
Added more concepts:
- Added IDictionary concept (std::map and other dictionary types)
- Added ISet concept (std::set and other set types)
Moved concepts logic to Internal ConceptHelpFunction
Bug fixes:
- IAray now has operator[]
- IDictionary fix operator[]
- readonly collections are still equal to the usual ones
</releaseNotes>
<version>0.1.2</version>
<version>0.1.3</version>
<authors>Konstantin Diachenko</authors>
<owners>Konstantin Diachenko</owners>
<copyright>Konstantin Diachenko</copyright>
Expand Down
1 change: 1 addition & 0 deletions cpp/Platform.Interfaces/Platform.Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define PLATFORM_INTERFACES

#include <concepts>
#include <ranges>

#include "IEnumerable.h"
#include "IArray.h"
Expand Down

0 comments on commit 6c1408e

Please sign in to comment.