Skip to content

Commit e9e7f64

Browse files
committed
Use constexpr when possible
WE2-1007 Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent ec1884c commit e9e7f64

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
#define PCSC_CPP_WARNING_DISABLE_MSVC(text)
5555
#endif
5656

57+
#ifdef __cpp_lib_constexpr_vector
58+
#define CONSTEXPR_VECTOR constexpr
59+
#else
60+
#define CONSTEXPR_VECTOR
61+
#endif
62+
5763
namespace pcsc_cpp
5864
{
5965

@@ -145,17 +151,20 @@ struct CommandApdu
145151
static constexpr size_t MAX_DATA_SIZE = 255;
146152

147153
// Case 1
148-
CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2) : d {cls, ins, p1, p2} {}
154+
CONSTEXPR_VECTOR CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2) :
155+
d {cls, ins, p1, p2}
156+
{
157+
}
149158

150159
// Case 2
151-
CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2, byte_type le) :
152-
d {cls, ins, p1, p2, le}
160+
CONSTEXPR_VECTOR CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2,
161+
byte_type le) : d {cls, ins, p1, p2, le}
153162
{
154163
}
155164

156165
// Case 3
157-
CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2, byte_vector data) :
158-
d {std::move(data)}
166+
CONSTEXPR_VECTOR CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2,
167+
byte_vector data) : d {std::move(data)}
159168
{
160169
if (d.size() > MAX_DATA_SIZE) {
161170
throw std::invalid_argument("Command chaining and extended lenght not supported");
@@ -164,8 +173,9 @@ struct CommandApdu
164173
}
165174

166175
// Case 4
167-
CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2, byte_vector data,
168-
byte_type le) : CommandApdu {cls, ins, p1, p2, std::move(data)}
176+
CONSTEXPR_VECTOR CommandApdu(byte_type cls, byte_type ins, byte_type p1, byte_type p2,
177+
byte_vector data, byte_type le) :
178+
CommandApdu {cls, ins, p1, p2, std::move(data)}
169179
{
170180
d.push_back(le);
171181
}

src/electronic-ids/pcsc/pcsc-common.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ inline pcsc_cpp::byte_vector getCertificate(pcsc_cpp::SmartCard& card,
4343
return readBinary(card, length, MAX_LE_VALUE);
4444
}
4545

46-
inline pcsc_cpp::byte_vector addPaddingToPin(pcsc_cpp::byte_vector&& pin, size_t paddingLength,
47-
pcsc_cpp::byte_type paddingChar)
46+
CONSTEXPR_VECTOR inline pcsc_cpp::byte_vector
47+
addPaddingToPin(pcsc_cpp::byte_vector&& pin, size_t paddingLength, pcsc_cpp::byte_type paddingChar)
4848
{
4949
pin.resize(std::max(pin.size(), paddingLength), paddingChar);
5050
return std::move(pin);

0 commit comments

Comments
 (0)