SIRIUS
7.5.0
Electronic structure library and applications
src
core
strong_type.hpp
Go to the documentation of this file.
1
// Copyright (c) 2013-2023 Anton Kozhevnikov, Thomas Schulthess
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5
// the following conditions are met:
6
//
7
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8
// following disclaimer.
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10
// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20
/** \file strong_type.hpp
21
*
22
* \brief A wrapper class to create strong types.
23
*/
24
25
#ifndef __STRONG_TYPE_HPP__
26
#define __STRONG_TYPE_HPP__
27
28
namespace
sirius
{
29
30
template
<
typename
T,
typename
Tag>
31
class
strong_type
32
{
33
private
:
34
T val_;
35
public
:
36
37
explicit
strong_type
(T
const
& val__)
38
: val_{val__}
39
{
40
}
41
42
explicit
strong_type
(T&& val__)
43
: val_{std::move(val__)}
44
{
45
}
46
47
inline
T get()
const
48
{
49
return
val_;
50
}
51
52
operator
T()
const
53
{
54
return
val_;
55
}
56
57
inline
bool
operator!=(
strong_type<T, Tag>
const
& rhs__)
58
{
59
return
this->val_ != rhs__.val_;
60
}
61
62
inline
bool
operator==(
strong_type<T, Tag>
const
& rhs__)
63
{
64
return
this->val_ == rhs__.val_;
65
}
66
67
inline
strong_type<T, Tag>
& operator++(
int
)
68
{
69
this->val_++;
70
return
*
this
;
71
}
72
inline
strong_type<T, Tag>
& operator+=(T rhs__)
73
{
74
this->val_ += rhs__;
75
return
*
this
;
76
}
77
};
78
79
}
80
81
#endif
sirius::strong_type
Definition:
strong_type.hpp:32
sirius
Namespace of the SIRIUS library.
Definition:
sirius.f90:5
Generated on Wed Nov 22 2023 17:00:16 for SIRIUS by
1.9.3