Skip to content

rhysd/FrozenString

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Frozen String Library Build Status

This library provides string which is constructible in both compile-time and runtime. std::string is modifiable and not immutable but frozen::string which this library provides is immutable and static.

Constexpr

#include "frozen/string.hpp"
#include <iostream>

using frozen::operator"" _fstr;


// construct string
constexpr frozen::string<10> s1 = "hoge";
constexpr auto s2 = frozen::make_string("hoge");

// immutable!
s1[0] = 'h'; // error!

// construct from numbers
constexpr auto answer = frozen::to_string(42); // from integer
constexpr auto pi = frozen::to_string(3.141592); // from floating point

// compare to string
s1 == frozen::make_string("hoge"); // true
s1 == "hoge?"; // false

// concat strings or numbers
s1 + frozen::make_string("poyo"); // "hogepoyo"
s1 + "poyo"; // "hogepoyo"
s1 + '!'; // "hoge!"
s1 + 42; // "hoge42"
s1 + 3.14; // "hoge3.14"
make_string("Today is ") + 8 + '/' + 5; // "Today is 8/5"

// output
std::cout << s1;

// conversion
s1.data(); // to char const *
s1.to_std_string(); // to std::string

// user defined literals
123.45_fstr; // "123.45"
42_fstr; // "12"
"hoge"_fstr; // "hoge"
u'ω'_fstr; // "ω"

// wide strings for wchar_t, char16_t, char32_t
frozen::wstring<13> ws1 = L"あああ";
auto ws2 = frozen::make_string(L"つらぽよ");
auto answer = frozen::to_u16string(3.14);

See example directory to see more examples.

Template level

Under construction.

Compiler Requirements

  • gcc : 4.8 or later
  • clang : 3.4 or later
  • Boost.PreProcessor for frozen::type template meta functions

Author

@Linda_pp

License

Copyright (c) 2013 rhysd

Distributed under the Boost Software License, Version 1.0.

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

About

C++ immutable string library in C++11 constexpr and type-level

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published