0

A C++ concept can be constructed by combining other concepts or a list of required expressions, with boolean operators.

When a class A inherits from B, there is only one relation (mostly resembles union). For a C++ concept, the relation to another concept can a be union, an intersection, and difference. Also the expression can contain sub-expressions, how to deal with that?

After digging around, I found this solution

@startuml
skinparam style strictuml
Hide empty members 

interface scalar<T>
interface arithmetic<T>
interface complex<T>

scalar *-- arithmetic : <<T>>
scalar *-- complex : <<T>>
complex *-- arithmetic : <<typename T::value_type>>
(scalar,arithmetic) ...  (scalar,complex) : {or}

interface complex {
T a
-- requires --
typename T::value_type
{method} {a.real()} -> same_as<typename T::value_type>
{method} {a.imag()} -> same_as<typename T::value_type>
}
@enduml

Which renders to

Example

Does this picture say convey that

A scalar may be arithmetic (read: a non-complex number) or a complex number. A complex number must have a value type (which is arithmetic), and accessors for real and imaginary parts.

?

7
  • 1
    Concepts can also represent the relationship between types, not just a thing a single type does in a vacuum. Nov 20, 2022 at 18:58
  • I'd treat concepts like interfaces in UML
    – Caleth
    Nov 21, 2022 at 10:50
  • What is the audience for your UML model? A natural language constraint is enough for documentation, but not for code generation or model checking stackoverflow.com/questions/44244891/… Nov 21, 2022 at 15:48
  • @Caleth The problem is that UML only does union between all inherited interfaces. You cannot say (A and B and not C) or D.
    – user877329
    Nov 21, 2022 at 18:59
  • 1
    Does this SO question on modeling concepts in UML answer your question? stackoverflow.com/a/63945090/3723423
    – Christophe
    Nov 21, 2022 at 20:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.