diff --git a/cpp/Platform.Interfaces/CLink.h b/cpp/Platform.Interfaces/CLink.h new file mode 100644 index 0000000..5f0671c --- /dev/null +++ b/cpp/Platform.Interfaces/CLink.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +namespace Platform::Interfaces { + template + concept CLink = requires(TSelf self) { + { self.empty() } -> std::same_as; + typename TSelf::value_type; + { self.begin } -> std::same_as; + { self.end } -> std::same_as; + }; + + template + struct Link { + using value_type = typename TSelf::value_type; + }; +} // namespace Platform::Interfaces \ No newline at end of file diff --git a/cpp/Platform.Interfaces/Platform.Interfaces.h b/cpp/Platform.Interfaces/Platform.Interfaces.h index e6cbd2f..c679cd1 100644 --- a/cpp/Platform.Interfaces/Platform.Interfaces.h +++ b/cpp/Platform.Interfaces/Platform.Interfaces.h @@ -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" diff --git a/examples/test_clink b/examples/test_clink new file mode 100755 index 0000000..7487aa3 Binary files /dev/null and b/examples/test_clink differ diff --git a/examples/test_clink.cpp b/examples/test_clink.cpp new file mode 100644 index 0000000..f61c637 --- /dev/null +++ b/examples/test_clink.cpp @@ -0,0 +1,50 @@ +#include "../cpp/Platform.Interfaces/Platform.Interfaces.h" +#include +#include + +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 should satisfy CLink concept"); + + // Test that BadTestLink does not satisfy CLink concept + static_assert(!CLink, "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::value_type, int>, + "Link helper should provide correct value_type"); + + std::cout << "All tests passed!" << std::endl; + return 0; +} \ No newline at end of file