TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25658 16
muopt: a C++17 micro-library for argument parsing

Hello! I wanted to share a project that I've been working on for the last few days, a small argument parsing library called muopt. It started from a quite popular Rust crate called lexopt that I use in one of my CLI Rust projects. I wanted something similar to lexopt and couldn't find it for C++, so I decided to write my own.

muopt is more of a tokenizer/lexer than it is a parser. It doesn't "connect" a value to its option and just views them as an argument. muopt is intended to be minimal and bare-bones. Below is a really simple example of muopt in action.

#include "muopt/muopt.hpp"
#include <iostream>

int main(int argc, char argv) {
muopt::Parser parser(argc, argv);

while (std::optional<muopt::Arg> arg = parser.next()) {
if (arg->islong("help"))
std::cout << "usage: example [--input FILE]\n";
if (arg->is
long("input"))
std::cout << parser.argvalue().valueor("") << '\n';
}
}

The code above will match the arguments --help and -h. Both will print out the usage message. It will also match --input=Hello or --input Hello and print out the value. The README has a deeper explanation on how muopt works and the repo has more examples.

muopt is still very early; it's not even released yet. I'm still debating on how to take on certain things, for example the arg_value() return type and how errors should be handled. Any suggestions are welcomed!

GitHub: https://github.com/secona/muopt

https://redd.it/1v6342h
@r_cpp
GitHub GitHub - secona/muopt: μopt - a C++17 micro-library for argument parsing μopt - a C++17 micro-library for argument parsing. Contribute to secona/muopt development by creating an account on GitHub.
More from @r_cpp
  1. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  2. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  3. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  4. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  5. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
  6. Sep 11, 2026MSVC C++23: constexpr cmath with LLVM Libc https://devblogs.microsoft.com/cppblog/msvc-c23…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →