Skip to content

Commit cc3b621

Browse files
committed
SalesData.hpp
1 parent 0537ff9 commit cc3b621

2 files changed

Lines changed: 38 additions & 9 deletions

File tree

section5/SalesData.hpp

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,45 @@ BEGIN_NAMESPACE(cpp_study)
1010
class SalesData final
1111
{
1212
public:
13-
using this_type = SalesData;
13+
using this_type = SalesData;
1414

1515
public:
16-
using string_type = std::string;
17-
using uint_type = unsigned int;
18-
using currency_type = double;
16+
using string_type = std::string;
17+
using string_view_type = const std::string&;
18+
using uint_type = unsigned int;
19+
using currency_type = double;
1920

2021
STATIC_ASSERT(sizeof(uint_type) >= 4);
2122
STATIC_ASSERT(sizeof(currency_type) >= 4);
2223
public:
24+
SalesData(string_view_type id, uint_type s, currency_type r) noexcept
25+
: m_id(id), m_sold(s), m_revenue(r)
26+
{}
27+
28+
SalesData(string_view_type id) noexcept
29+
: SalesData(id, 0, 0)
30+
{}
31+
32+
public:
33+
SalesData(SalesData&& s) noexcept
34+
{
35+
m_id = std::move(s.m_id);
36+
m_sold = s.m_sold;
37+
m_revenue = s.m_revenue;
38+
}
39+
40+
SalesData& operator=(SalesData&& s) noexcept
41+
{
42+
m_id = std::move(s.m_id);
43+
m_sold = s.m_sold;
44+
m_revenue = s.m_revenue;
45+
46+
return *this;
47+
}
48+
49+
SalesData(const SalesData&) = default;
50+
SalesData& operator=(const SalesData&) = default;
51+
2352
SalesData() = default;
2453
~SalesData() = default;
2554

@@ -29,17 +58,17 @@ class SalesData final
2958
uint_type m_revenue = 0;
3059

3160
public:
32-
const string_type& id() const
61+
string_view_type id() const noexcept
3362
{
3463
return m_id;
3564
}
3665

37-
uint_type sold() const
66+
uint_type sold() const noexcept
3867
{
3968
return m_sold;
4069
}
4170

42-
currency_type revenue() const
71+
currency_type revenue() const noexcept
4372
{
4473
return m_revenue;
4574
}

section5/cpplang.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// must be C++11 or later
2020
#if __cplusplus < 201103
2121
# error "C++ is too old"
22-
#endif // __cplusplus >= 201402
22+
#endif // __cplusplus < 201103
2323

2424
// [[deprecated]]
2525
#if __cplusplus >= 201402
@@ -32,7 +32,7 @@
3232
#if __cpp_static_assert >= 201411
3333
# define STATIC_ASSERT(x) static_assert(x)
3434
#else
35-
# define STATIC_ASSERT(x) static_assert(x, "")
35+
# define STATIC_ASSERT(x) static_assert(x, #x)
3636
#endif
3737

3838
// macro for convienient namespace

0 commit comments

Comments
 (0)