Skip to content

WinterWind33/verso

Repository files navigation

verso - A simple C++ semantic versioning library

verso is a simple header-only C++ library for supporting semantic versioning in C++ projects. The library is written and requires C++ 20, so make sure your compiler supports it.

The library has one header file, verso/verso.hpp, just include it in your project and you're ready to go. The library does not have any third-party dependencies.

Enjoy!

Build status

Linux x64 GCC Build Windows x64 MSVC Build MacOS x64 Clang Build

Getting verso

You can get verso by cloning this repository, making it a submodule in your project, or downloading the single header file.

Cloning the repository

You can clone the repository:

git clone https://github.com/WinterWind33/verso.git
cd verso

As a project submodule

If you want to include verso as a submodule in your project:

git submodule add https://github.com/WinterWind33/verso.git
git submodule update --init --recursive

After this, you can use CMake to include verso in your project:

# You need to have CMake 3.19+
add_subdirectory(path/to/verso)
target_link_libraries(your_target PRIVATE verso)

And you're ready to go!

Getting started with verso

To get started with verso, just include the header file in your C++ source code:

#include <verso/verso.hpp>

And then you can start using the classes and functions in the verso namespace:

verso::version ver{1, 2, 3}; // Creates a version 1.2.3

// Setting version numbers
ver.major(2); // Now version is 2.2.3
ver.minor(1); // Now version is 2.1.3
ver.patch(3); // Now version is 2.1.3
std::cout << "Version: " << verso::to_string(ver) << '\n'; // Version: 2.1.3

Structured bindings:

// Structured binding
// major = 2, minor = 1, patch = 3, prerelease_data = std::nullopt, build_metadata = std::nullopt
auto [major, minor, patch, prerelease_data, build_metadata] = verso::components(ver);

Parsing versions from strings:

std::optional<verso::version> parsed_ver = verso::from_string<verso::version>("1.43.5");
assert(parsed_ver.has_value());

const auto major = parsed_ver->major(); // 1
const auto minor = parsed_ver->minor(); // 43
const auto patch = parsed_ver->patch(); // 5

Comparing versions:

const verso::version ver1{1, 0, 0};
const verso::version ver2{1, 0, 1};
const verso::version ver3{1, 0, 0, "alpha"};

// true
bool res = ver1 < ver2;
// true, because pre-release versions have lower precedence than the associated normal version
res = ver1 > ver3;

You can find the full getting started guide in the docs/getting-started.md file and more examples in the examples directory.

Development documentation

Make sure to read the docs/CONTRIBUTING.md file for guidelines on contributing to the project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Simple semantic versioning C++ 20 library

Topics

Resources

License

Contributing

Stars

1 star

Watchers

1 watching

Forks

Contributors