Giter VIP home page Giter VIP logo

string_constant's Introduction

#string_constant

C++ implementation of compile time evaluated strings. This library provides basic compile time strings as well as features for fmt and std::string_view.

Usage

The library can be included into your existing CMake project by using git submodules and adding the following lines to your CMakeLists.txt:

add_subdirectory(string_constant)
target_link_libraries(${target_name} string_constant::string_constant)

If you are not using git submodules and want to use the fetch content feature of CMake, just add the following lines to your CMakeLists.txt:

include(FetchContent)
FetchContent_Declare(
    string_constant
    GIT_REPOSITORY [email protected]:dominicpoeschko/string_constant.git
    GIT_TAG master
)
FetchContent_MakeAvailable(string_constant)
target_link_libraries(${target_name} string_constant::string_constant)

Examples

To build the examples go into the examples directory and run the following commands:

mkdir build
cd build
cmake ..
make

The most basic usage can be found in examples/basic_usage.cpp, which covers basic string manipulation as well as printing through std::cout and fmt::print.

#include "string_constant/string_constant.hpp"
#include <fmt/format.h>
#include <iostream>


int main(){
    using namespace sc::literals;
    static constexpr auto foo = "foobar"_sc;
    static constexpr auto bar = "this is"_sc;
    static constexpr auto foobar = foo + " "_sc +  bar;

    static_assert(foobar == "foobar this is"_sc);
    
    std::cout << foo << " + " << bar << " = "
            << foobar << std::endl;
    
    fmt::print("{} + {} = {}\n", foo, bar, foobar);
    return 0;
}

For the usage with compile-time format and the usage with std::string_view see the other examples.

string_constant's People

Contributors

dominicpoeschko avatar useless-branch avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.