File: virtual_traits.adoc

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (93 lines) | stat: -rw-r--r-- 2,280 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

## virtual_traits

### Synopsis

Defined in <boost/openmethod/core.hpp>.

```c++
namespace boost::openmethod {

template<class, class>
struct virtual_traits; // not defined

template<class Class, class Policy>
struct virtual_traits<..., Policy> {
    using virtual_type = ...;
    static auto peek(const T& arg) -> const ...&;
    template<typename Derived> static auto cast(T& obj) -> ...;
    template<class Other> using rebind = ...; // for smart virtual pointers
};

}
```

### Description

Specializations of `virtual_traits` provide an interface for `method` and
`virtual_ptr` to manipulate virtual arguments.

### Specializations

Specializations are provided for:

* `virtual_ptr<T, Policy>`
* `const virtual_ptr<T, Policy>&`
* `T&`
* `T&&`
* `T*`
* `std::shared_ptr<T>`: defined in <boost/openmethod/interop/std_shared_ptr.hpp>
* `const std::shared_ptr<T>&`: defined in <boost/openmethod/interop/std_shared_ptr.hpp>
* `std::unique_ptr<T>`: defined in <boost/openmethod/interop/std_unique_ptr.hpp>

### Members

#### virtual_type

```c++
using virtual_type = ...;
```

The class used for method selection. It must be registered in Policy.

For example, `virtual_type` in the following specializations are all `Class`:

* `virtual_traits<virtual_ptr<Class, Policy>>`
* `virtual_traits<const virtual_ptr<std::shared_ptr<Class>&, Policy>`
* `virtual_traits<Class&, Policy>`
* `virtual_traits<const std::shared_ptr<Class>&, Policy>`

#### peek

```c++
static auto peek(T arg) -> const ...&;
```

Returns a value for the purpose of obtaining a v-table pointer for `arg`.

For example, `peek` returns a `const T&` for a `T&`, a `const T&`, a `T&&`, and
a `std::shared_ptr<T>`; and a `const virtual_ptr<Class, Policy>&` for a
`const virtual_ptr<Class, Policy>&`.


#### cast

```c++
template<typename Derived>
static decltype(auto) cast(T& obj);
```

Casts argument `obj` to the type expected by an overrider.

For example, if a method takes a `virtual_<Animal&>`, an overrider for `Cat&`
uses `virtual_traits` to cast a `Animal&` to a `Cat&`.

#### rebind

```c++
template<class Other> using rebind = ...;
```

For smart pointers only. Rebinds the smart pointer to a different type. For
example, `virtual_traits<std::shared_ptr<T>, Policy>::rebind<U>` is
`std::shared_ptr<U>`.