Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Allow to compile with C++17 #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ cmake ..
make install
```

The library can also be build with `c++17` by using `-DCMAKE_CXX_STANDARD=17`
which enables `std::string_view` support.

## Running tests

After compiling as described above you should get two files: `libcrossguid.a` (the
Expand Down
9 changes: 7 additions & 2 deletions include/crossguid/guid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ BEGIN_XG_NAMESPACE
class Guid
{
public:
Guid();

explicit Guid(const std::array<unsigned char, 16> &bytes);
explicit Guid(std::array<unsigned char, 16> &&bytes);

#if __cplusplus >= 201703L
explicit Guid(std::string_view fromString);
Guid();

#else
explicit Guid(std::string fromString);
#endif

Guid(const Guid &other) = default;
Guid &operator=(const Guid &other) = default;
Guid(Guid &&other) = default;
Expand Down
4 changes: 4 additions & 0 deletions src/guid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ unsigned char hexPairToChar(char a, char b)
}

// create a guid from string
#if __cplusplus >= 201703L
Guid::Guid(std::string_view fromString)
#else
Guid::Guid(std::string fromString)
#endif
{
char charOne = '\0';
char charTwo = '\0';
Expand Down