boostorg / boostorg/histogram

Introducing `variable_t` and similar types for convenience

Open
#378 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
334
Forks
76
PR merge metrics
No merged PRs in 30d

Description

@HDembinski Here are some examples why using `variable_t` can bring convenience.

```C++
std::is_same_v<
boost::histogram::axis::variable,
boost::histogram::axis::variable
>
```
is `false`,
```C++
std::is_same_v<
boost::histogram::axis::variable_t,
boost::histogram::axis::variable_t
>
```
is `true`;

---

This causes a compile error:
```C++
boost::histogram::axis::variable a;
boost::histogram::axis::variable b;
a = b;
```
This does not cause a compile error:
```C++
boost::histogram::axis::variable_t a;
boost::histogram::axis::variable_t b;
a = b;
```

---

In templates, you can get the meta type, options type, allocator type conveniently if template users write `variable_t`, not if template users write `variable`:
```
template
void f(boost::histogram::axis::variable)
{
std::cout << typeid(V).name() << '\n';
std::cout << typeid(M).name() << '\n';
std::cout << typeid(O).name() << '\n';
std::cout << typeid(A).name() << '\n';
}

int main(int argc, char *argv[])
{
f(boost::histogram::axis::variable<>());
//double
//struct boost::use_default
//struct boost::use_default
//class std::allocator

f(boost::histogram::axis::variable_t<>());
//double
//class std::basic_string,class std::allocator >
//struct boost::histogram::axis::option::bitset<3>
//class std::allocator
}
```

---

In debugger, you can not see what options `a` has but can see what options `b` has:
![image](https://user-images.githubusercontent.com/5171262/209428440-790b9979-b09b-475a-b231-45c61ae69506.png)
```C++
boost::histogram::axis::variable<> a;
boost::histogram::axis::variable_t<> b;
```

_Originally posted by @jhcarl0814 in https://github.com/boostorg/histogram/issues/372#issuecomment-1364494250_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.