Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cpp/Platform.Interfaces/CLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <concepts>
#include <type_traits>

namespace Platform::Interfaces {
template <typename TSelf>
concept CLink = requires(TSelf self) {
{ self.empty() } -> std::same_as<bool>;
typename TSelf::value_type;
{ self.begin } -> std::same_as<typename TSelf::value_type&>;
{ self.end } -> std::same_as<typename TSelf::value_type&>;
};

template <CLink TSelf>
struct Link {
using value_type = typename TSelf::value_type;
};
} // namespace Platform::Interfaces
2 changes: 2 additions & 0 deletions cpp/Platform.Interfaces/Platform.Interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "CCounter.h"
#include "CCriterionMatcher.h"
#include "CFactory.h"
#include "CLink.h"
#include "CLinkAddress.h"
#include "CProperties.h"
#include "CProvider.h"
#include "CSetter.h"
Expand Down
Binary file added examples/test_clink
Binary file not shown.
50 changes: 50 additions & 0 deletions examples/test_clink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "../cpp/Platform.Interfaces/Platform.Interfaces.h"
#include <iostream>
#include <cassert>

using namespace Platform::Interfaces;

// Test implementation that satisfies CLink concept
struct TestLink {
using value_type = int;

value_type begin;
value_type end;

TestLink(int b, int e) : begin(b), end(e) {}

bool empty() const {
return begin == end;
}
};

// Test implementation that does NOT satisfy CLink concept (missing empty method)
struct BadTestLink {
using value_type = int;
value_type begin;
value_type end;
};

int main() {
// Test that TestLink satisfies CLink concept
static_assert(CLink<TestLink>, "TestLink should satisfy CLink concept");

// Test that BadTestLink does not satisfy CLink concept
static_assert(!CLink<BadTestLink>, "BadTestLink should NOT satisfy CLink concept");

// Test runtime behavior
TestLink link1(5, 10);
TestLink link2(5, 5);

assert(!link1.empty());
assert(link2.empty());
assert(link1.begin == 5);
assert(link1.end == 10);

// Test Link helper struct
static_assert(std::same_as<Link<TestLink>::value_type, int>,
"Link helper should provide correct value_type");

std::cout << "All tests passed!" << std::endl;
return 0;
}
Loading