from Microsoft STL, but multi-platform

Overview

mscharconv

<charconv> from Microsoft STL, but multi-platform.

Tested with MSVC, gcc, and clang on Windows, Linux, and macOS (will likely work on other platforms supported by any of these compilers)

Usage

The library is header only. You can clone the repo or copy the contents of the include directory in your project.

Alternatively you can use with CMake. The provided CMakeLists.txt defines an INTERFACE target mscharconv.

To use the library in your code simply include <msstl/charconv.hpp> and use to_chars and from_chars from the namespace msstl.

C++17 or later is needed.

Example

#include <msstl/charconv.hpp>
#include <iostream>
#include <string_view>

int main() {
    std::string_view pi_str = "3.14159 is pi";
    double pi;
    auto [p, ec] = msstl::from_chars(pi_str.data(), pi_str.data() + pi_str.length(), pi);
    if (ec != std::errc{}) {
        std::cerr << "Error converting \"" << pi_str << "\" to double\n";
        return 1;
    }
    std::cout << "Got double " << pi << ". The rest is \"" << p << "\".\n";

    return 0;
}

Additional Utilities

An additional header util.hpp is provided with the library with non-standard util functions in namespace msstl::util. Note that util.hpp is NOT self contained. You must include it after including charconv.hpp.

The utility functions are:

  • bool from_string(std::string_view str, INTEGER& out, int base = 10); - convert string to integral number with a given base. Will return true if the conversion is successful. The string must be an integer and nothing more. Even though from_chars supports inputs like "123 and some text" and will stop at the first non-integer character, from_string will consider this to be an invalid input and return false.
  • bool from_string(std::string_view str, FLOATING_POINT_NUM& out); - convert a string to a floating point number. Return true is successful. Same restrictions as above apply.

Advanced usage

For the basic usage of the library one needs to include charconv.hpp which is quite big. It contains a lot of code and huge helper arrays. If you include charconv in many places of your code, it may lead to long compilation times. The advanced usage of the library allows the functions to be compiled separately and only once per project. To enable this, instead of including charconv.hpp include charconv_fwd.hpp and in a single place of your code define MSCHARCONV_IMPLEMENT and then include charconv.hpp.

Additionally if you want to provide a shared library interface to the functions, define MSCHARCONV_API to your import/export symbols, before including charconv_fwd.hpp

Development

The library is created by automatically converting headers from a clone of Microsoft STL with the Ruby script convert-msstl-files.rb. Additionally support functions and macros are provided in charconv_impl.inl.

License

Copyright (c) Microsoft Corporation, Borislav Stanimirov, and contributors.

SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

You might also like...
Linux multi-touch gesture recognizer
Linux multi-touch gesture recognizer

Follow Touchégg on... Touchégg Touchégg is an app that runs in the background and transform the gestures you make on your touchpad or touchscreen into

Port of the 2020 support library to Raspberry Pi for the VL53L3CX Time-of-Flight ranging sensor with advanced multi-object detection

Port of ST VL53L3CX (2020) driver library to Raspberry Pi This is a port of the support library to Raspberry Pi for the VL53L3CX Time-of-Flight rangin

SIMULATeQCD is a multi-GPU Lattice QCD framework that makes it simple and easy for physicists to implement lattice QCD formulas while still providing the best possible performance.

SIMULATeQCD a SImple MUlti-GPU LATtice code for QCD calculations SIMULATeQCD is a multi-GPU Lattice QCD framework that makes it simple and easy for ph

Multi-tap FDN reverb
Multi-tap FDN reverb

Eko Multi-tap Diffusion Network reverb Modelled on the Rounds Reverb by native istruments with some additional features not found on the orginal. Eko

A program developed using MPI for distributed computation of Histogram for large data and their performance anaysis on multi-core systems
A program developed using MPI for distributed computation of Histogram for large data and their performance anaysis on multi-core systems

mpi-histo A program developed using MPI for distributed computation of Histogram for large data and their performance anaysis on multi-core systems. T

Tandem - [CoRL 21'] TANDEM: Tracking and Dense Mapping in Real-time using Deep Multi-view Stereo
Tandem - [CoRL 21'] TANDEM: Tracking and Dense Mapping in Real-time using Deep Multi-view Stereo

TANDEM: Tracking and Dense Mapping in Real-time using Deep Multi-view Stereo Lukas Koestler1*    Nan Yang1,2*,†    Niclas Zeller2,3    Daniel Cremers1

Multi-Scale Representation Learning on Proteins

Multi-Scale Representation Learning on Proteins (Under Construction and Subject to Change) Pending: Update links for dataset. This is the official PyT

Distributed machine learning platform

Veles Distributed platform for rapid Deep learning application development Consists of: Platform - https://github.com/Samsung/veles Znicz Plugin - Neu

Hopsworks - Data-Intensive AI platform with a Feature Store
Hopsworks - Data-Intensive AI platform with a Feature Store

Give us a star if you appreciate what we do What is Hopsworks? Quick Start Development and Operational ML on Hopsworks Docs Who’s behind Hopsworks? Op

Comments
  • Usage of ulong32

    Usage of ulong32

    Hello!

    Recommend changing ulong32 to use cstdint's uint32_t. uint32_t is needed be some of the builtin's used and gets flagged as a conversion error on latest clang. I've also added some static_casts in order to allow compilation under werror.

    msstl.zip

    opened by seppeon 5
  • Not compiling on MSVC

    Not compiling on MSVC

    Hi,

    I've imported your library in my project because I have a need for cross-platform <charconv>. The library works fine with GCC on MacOS (built with iOS SDK 15.0).

    However, on Windows, compilation errors occurs when trying to compile for x64 target architecture with MSVC compiler. The error occurs in charconv.inl, like this:

    include\third_party\msstl\converted\charconv.inl(476,111): error C2664: 'uint32_t msstl::impl::_Bit_scan_reverse(const msstl::impl::_Big_integer_flt &) noexcept': cannot convert argument 1 from 'uint32_t' to 'const msstl::impl::_Big_integer_flt &'
    
    include\third_party\msstl\converted\charconv.inl(476,111): message : Reason: cannot convert from 'uint32_t' to 'const msstl::impl::_Big_integer_flt'
    
    include\third_party\msstl\converted\charconv.inl(476,111): message : No constructor could take the source type, or constructor overload resolution was ambiguous
    
    include\third_party\msstl\converted\charconv.inl(439,31): message : see declaration of 'msstl::impl::_Bit_scan_reverse'
    
    

    Here is the list of options used when compiling: (minus the build folder and output arguments)

    /JMC /permissive- /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Zc:inline /fp:precise /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_WARNINGS" /D "_UNICODE" /D "UNICODE" /D "DEBUGLOG" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++17 /FC  /EHsc /nologo  /diagnostics:column 
    

    I wonder why the function _Bit_scan_reverse would be used with an argument of type uint32_t ? Seems like it'd be more likely used on your custom structures.

    Thanks in advance for replying (if you still maintain this of course :) )

    opened by yghdj 3
Owner
Borislav Stanimirov
A (mostly) C++ programmer
Borislav Stanimirov
Low dependency(C++11 STL only), good portability, header-only, deep neural networks for embedded

LKYDeepNN LKYDeepNN 可訓練的深度類神經網路 (Deep Neural Network) 函式庫。 輕量,核心部份只依賴 C++11 標準函式庫,低相依性、好移植,方便在嵌入式系統上使用。 Class diagram 附有訓練視覺化 demo 程式 訓練視覺化程式以 OpenCV

Lin Kao-Yuan 44 Nov 7, 2022
Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit

CNTK Chat Windows build status Linux build status The Microsoft Cognitive Toolkit (https://cntk.ai) is a unified deep learning toolkit that describes

Microsoft 17.3k Dec 23, 2022
EdgeKiller is a simple application that fully replaces Microsoft Edge with the Browser of choice.

EdgeKiller EdgeKiller is a simple application that fully replaces Microsoft Edge with the Browser of choice, while also intercepting all the microsoft

Jan Ochwat 2 Nov 30, 2021
Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit

The Microsoft Cognitive Toolkit is a unified deep learning toolkit that describes neural networks as a series of computational steps via a directed graph.

Microsoft 17.3k Jan 6, 2023
A custom GEGL filter that does layer effects. It may not be non-destructive but you can make presets of your favorite text styles

A custom GEGL filter that does layer effects. It may not be non-destructive but you can make presets of your favorite text styles. Futures plans are going to include an image file overlay, and pro tip you can do a multistroke if sacrifice a shadow/glow.

null 11 Jan 2, 2023
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation

Build Type Linux MacOS Windows Build Status OpenPose has represented the first real-time multi-person system to jointly detect human body, hand, facia

null 25.6k Dec 29, 2022
SecMML: Secure MPC(multi-party computation) Machine Learning Framework

SecMML 介绍 SecMML是FudanMPL(Multi-Party Computation + Machine Learning)的一个分支,是用于训练机器学习模型的高效可扩展的安全多方计算(MPC)框架,基于BGW协议实现。此框架可以应用到三个及以上参与方联合训练的场景中。目前,SecMM

null 90 Dec 27, 2022
YOLOv4 accelerated wtih TensorRT and multi-stream input using Deepstream

Deepstream 5.1 YOLOv4 App This Deepstream application showcases YOLOv4 running at high FPS throughput! P.S - Click the gif to watch the entire video!

Akash James 35 Nov 10, 2022
A multi object tracking Library Based on tensorrt

YoloV5_JDE_TensorRT_for_Track Introduction A multi object detect and track Library Based on tensorrt 一个基于TensorRT的多目标检测和跟踪融合算法库,可以同时支持行人的多目标检测和跟踪,当然也可

zwg_cv 48 Nov 25, 2022
ORB-SLAM3 is the first real-time SLAM library able to perform Visual, Visual-Inertial and Multi-Map SLAM with monocular, stereo and RGB-D cameras, using pin-hole and fisheye lens models.

Just to test for my research, and I add coordinate transformation to evaluate the ORB_SLAM3. Only applied in research, and respect the authors' all work.

B.X.W 5 Jul 11, 2022