Awesome Open Source
Awesome Open Source

Not Enough Standards

Not Enough Standards is a modern header-only C++17 and C++20 library that provides platform-independent utilities. The goal of this library is to extend the standard library with recurent features, such as process management, shared library loading or thread pools. To reach that goal the library is written in a very standard compliant way, from the coding-style to the naming convention.

Features

Not Enough Standards works on any posix-compliant system and also on Windows.

Check out the Wiki for more informations.

Installation

Not Enough Standards requires a C++17 compiler, and a C++20 compiler for thread pools.

As any header only library, Not Enough Standards is designed to be directly included in your project, by copying the files you need in your project's directory.

You may also use it as a CMake subproject using add_subdirectory, and use it as any other library:

target_link_libraries(xxx not_enough_standards)
target_include_directories(xxx PRIVATE ${NES_INCLUDE_DIR})

The files of the library are independent from each others, so if you only need one specific feature, you can use only the header that contains it.
Actually the only file with a dependency is process.hpp which defines more features if pipe.hpp is available.

Usage

Here is a short example using Not Enough Standards:

main.cpp

#include <iostream>
#include <nes/process.hpp>

int main()
{
    //nes::this_process namespace can be used to modify current process or get informations about it.
    std::cout << "Current process has id " << nes::this_process::get_id() << std::endl; 
    std::cout << "Its current directory is \"" << nes::this_process::working_directory() << "\"" << std::endl;

    //Create a child process
    nes::process other{"other_process", {"Hey!", "\\\"12\"\"\\\\", "\\42\\", "It's \"me\"!"}, nes::process_options::grab_stdout};
    
    //Read the entire standard output of the child process. (nes::process_options::grab_stdout must be specified on process creation)
    std::cout << other.stdout_stream().rdbuf() << std::endl;

    //As a std::thread, a nes::process must be joined if it is not detached.
    if(other.joinable())
        other.join();

    //Once joined, we can check its return code.
    std::cout << "Other process ended with code: " << other.return_code() << std::endl;
}

other.cpp

#include <iostream>
#include <nes/process.hpp>

int main(int argc, char** argv)
{
    //Output some informations about this process
    std::cout << "Hello world! I'm Other!\n";
    std::cout << "You gave me " << argc << " arguments:";
    for(int i{}; i < argc; ++i)
        std::cout << "[" << argv[i] << "] ";
    std::cout << '\n';
    std::cout << "My working directory is \"" << nes::this_process::working_directory() << "\"" << std::endl;
}

Output

Current process has id 3612
Its current directory is "/..."
Hello world! I'm Other!
You gave me 5 arguments:[not_enough_standards_other.exe] [Hey!] [\"12""\\\] [\42\] [It's "me"!] 
My working directory is "/..."

Other process ended with code: 0

License

Not Enough Standards use the MIT license.


Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
C Plus Plus (369,955
Cpp (15,816
Cpp17 (1,808
Process (650
Utility Library (414
Cpp20 (400
Thread Pool (352
Mutex (192
Related Projects