494 lines
12 KiB
Markdown
494 lines
12 KiB
Markdown
# t00058 - Test case for concepts with variadic parameters and type aliases
|
|
## Config
|
|
```yaml
|
|
diagrams:
|
|
t00058_class:
|
|
type: class
|
|
glob:
|
|
- t00058.cc
|
|
include:
|
|
namespaces:
|
|
- clanguml::t00058
|
|
using_namespace: clanguml::t00058
|
|
plantuml:
|
|
after:
|
|
- '{{ alias("same_as_first_type<T,Args...>") }} ..> {{ alias("first_type<T,Args...>") }}'
|
|
mermaid:
|
|
after:
|
|
- '{{ alias("same_as_first_type<T,Args...>") }} ..> {{ alias("first_type<T,Args...>") }}'
|
|
```
|
|
## Source code
|
|
File `tests/t00058/t00058.cc`
|
|
```cpp
|
|
#include <string>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
|
|
// Based on a blog post:
|
|
// https://andreasfertig.blog/2020/08/cpp20-concepts-testing-constrained-functions/
|
|
|
|
namespace clanguml {
|
|
namespace t00058 {
|
|
|
|
template <typename T, typename... Args> struct first_type {
|
|
using type = T;
|
|
};
|
|
|
|
template <typename... Args>
|
|
using first_type_t = typename first_type<Args...>::type;
|
|
|
|
// TODO: Dependency of this concept on first_type<> template does not currently
|
|
// work due to the fact that I don't know how to extract that information
|
|
// from clang::DependentNameType to which first_type_t<> resolves to...
|
|
template <typename T, typename... Args>
|
|
concept same_as_first_type = std::is_same_v<std::remove_cvref_t<T>,
|
|
std::remove_cvref_t<first_type_t<Args...>>>;
|
|
|
|
template <typename T, typename... Args>
|
|
requires same_as_first_type<T, Args...>
|
|
struct A {
|
|
std::vector<T> a;
|
|
};
|
|
|
|
template <typename T, typename P, typename... Args>
|
|
requires same_as_first_type<T, Args...>
|
|
struct B {
|
|
std::vector<T> b;
|
|
P bb;
|
|
};
|
|
|
|
struct R {
|
|
A<int, int, double, std::string> aa;
|
|
B<int, std::string, int, double, A<int, int>> bb;
|
|
};
|
|
|
|
}
|
|
}
|
|
```
|
|
## Generated PlantUML diagrams
|
|

|
|
## Generated Mermaid diagrams
|
|

|
|
## Generated JSON models
|
|
```json
|
|
{
|
|
"diagram_type": "class",
|
|
"elements": [
|
|
{
|
|
"bases": [],
|
|
"display_name": "first_type<T,Args...>",
|
|
"id": "315695546090157538",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": true,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [],
|
|
"methods": [],
|
|
"name": "first_type",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 48,
|
|
"file": "t00058.cc",
|
|
"line": 11,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "template_type",
|
|
"name": "T",
|
|
"template_parameters": []
|
|
},
|
|
{
|
|
"is_variadic": true,
|
|
"kind": "template_type",
|
|
"name": "Args...",
|
|
"template_parameters": []
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"display_name": "same_as_first_type<T,Args...>",
|
|
"id": "13806561892589130461",
|
|
"name": "same_as_first_type",
|
|
"namespace": "clanguml::t00058",
|
|
"parameters": [],
|
|
"source_location": {
|
|
"column": 9,
|
|
"file": "t00058.cc",
|
|
"line": 22,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"statements": [],
|
|
"type": "concept"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "A<T,Args...>",
|
|
"id": "6388954776038573618",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": true,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [
|
|
{
|
|
"access": "public",
|
|
"is_static": false,
|
|
"name": "a",
|
|
"source_location": {
|
|
"column": 20,
|
|
"file": "t00058.cc",
|
|
"line": 28,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"type": "std::vector<T>"
|
|
}
|
|
],
|
|
"methods": [],
|
|
"name": "A",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 27,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "template_type",
|
|
"name": "T",
|
|
"template_parameters": []
|
|
},
|
|
{
|
|
"is_variadic": true,
|
|
"kind": "template_type",
|
|
"name": "Args...",
|
|
"template_parameters": []
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "B<T,P,Args...>",
|
|
"id": "3364759117572731240",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": true,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [
|
|
{
|
|
"access": "public",
|
|
"is_static": false,
|
|
"name": "b",
|
|
"source_location": {
|
|
"column": 20,
|
|
"file": "t00058.cc",
|
|
"line": 34,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"type": "std::vector<T>"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"is_static": false,
|
|
"name": "bb",
|
|
"source_location": {
|
|
"column": 7,
|
|
"file": "t00058.cc",
|
|
"line": 35,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"type": "P"
|
|
}
|
|
],
|
|
"methods": [],
|
|
"name": "B",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 33,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "template_type",
|
|
"name": "T",
|
|
"template_parameters": []
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "template_type",
|
|
"name": "P",
|
|
"template_parameters": []
|
|
},
|
|
{
|
|
"is_variadic": true,
|
|
"kind": "template_type",
|
|
"name": "Args...",
|
|
"template_parameters": []
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "A<int,int,double,std::string>",
|
|
"id": "13792017467641431843",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": false,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [],
|
|
"methods": [],
|
|
"name": "A",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 27,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "double"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "std::string"
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "A<int,int>",
|
|
"id": "10979049855252162226",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": true,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [],
|
|
"methods": [],
|
|
"name": "A",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 33,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "B<int,std::string,int,double,A<int,int>>",
|
|
"id": "2323064644481041066",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": false,
|
|
"is_template": true,
|
|
"is_union": false,
|
|
"members": [],
|
|
"methods": [],
|
|
"name": "B",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 33,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "std::string"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "double"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
},
|
|
{
|
|
"is_variadic": false,
|
|
"kind": "argument",
|
|
"template_parameters": [],
|
|
"type": "int"
|
|
}
|
|
],
|
|
"type": "A"
|
|
}
|
|
],
|
|
"type": "class"
|
|
},
|
|
{
|
|
"bases": [],
|
|
"display_name": "R",
|
|
"id": "8120865277594080075",
|
|
"is_abstract": false,
|
|
"is_nested": false,
|
|
"is_struct": true,
|
|
"is_template": false,
|
|
"is_union": false,
|
|
"members": [
|
|
{
|
|
"access": "public",
|
|
"is_static": false,
|
|
"name": "aa",
|
|
"source_location": {
|
|
"column": 38,
|
|
"file": "t00058.cc",
|
|
"line": 39,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"type": "A<int,int,double,std::string>"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"is_static": false,
|
|
"name": "bb",
|
|
"source_location": {
|
|
"column": 51,
|
|
"file": "t00058.cc",
|
|
"line": 40,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"type": "B<int,std::string,int,double,A<int,int>>"
|
|
}
|
|
],
|
|
"methods": [],
|
|
"name": "R",
|
|
"namespace": "clanguml::t00058",
|
|
"source_location": {
|
|
"column": 8,
|
|
"file": "t00058.cc",
|
|
"line": 38,
|
|
"translation_unit": "t00058.cc"
|
|
},
|
|
"template_parameters": [],
|
|
"type": "class"
|
|
}
|
|
],
|
|
"name": "t00058_class",
|
|
"package_type": "namespace",
|
|
"relationships": [
|
|
{
|
|
"destination": "13806561892589130461",
|
|
"label": "T,Args...",
|
|
"source": "6388954776038573618",
|
|
"type": "constraint"
|
|
},
|
|
{
|
|
"destination": "13806561892589130461",
|
|
"label": "T,Args...",
|
|
"source": "3364759117572731240",
|
|
"type": "constraint"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "6388954776038573618",
|
|
"source": "13792017467641431843",
|
|
"type": "instantiation"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "6388954776038573618",
|
|
"source": "10979049855252162226",
|
|
"type": "instantiation"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "10979049855252162226",
|
|
"source": "2323064644481041066",
|
|
"type": "dependency"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "3364759117572731240",
|
|
"source": "2323064644481041066",
|
|
"type": "instantiation"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "13792017467641431843",
|
|
"label": "aa",
|
|
"source": "8120865277594080075",
|
|
"type": "aggregation"
|
|
},
|
|
{
|
|
"access": "public",
|
|
"destination": "2323064644481041066",
|
|
"label": "bb",
|
|
"source": "8120865277594080075",
|
|
"type": "aggregation"
|
|
}
|
|
],
|
|
"using_namespace": "clanguml::t00058"
|
|
}
|
|
```
|