Skip to content

Instantly share code, notes, and snippets.

@dlOuOlb
Created November 5, 2022 03:46
Show Gist options
  • Save dlOuOlb/a5193553067a06d33b044195c07cc75c to your computer and use it in GitHub Desktop.
Save dlOuOlb/a5193553067a06d33b044195c07cc75c to your computer and use it in GitHub Desktop.
The C++ main function with read-only string arguments.

Summary

flowchart TB
	Old.Count("signed int") & Old.Array("char **") --> New.Class

	subgraph Old.Main["main"]
		New.Class("std::vector<std::string>") --> New.Main["Main"]
	end

	Old.Main --> Old.State.Success(["0"]) -..- Old.State("signed int")
Loading
#if __cplusplus < 201103L
# error "This code requires a C++11 compiler."
#else
# include <string> /* std::string */
# include <vector> /* std::vector */
extern R"(C++)" auto Main( const std::vector<std::string> & ) noexcept( false ) -> void;
extern R"(C++)" auto main( const signed int argc, char **const argv ) noexcept( false ) -> signed int { return Main( { argv, argv + argc } ), 0; }
#endif
#if __cplusplus < 201103L
# error "This code requires a C++11 compiler."
#else
# include <iostream> /* std::(cout|endl) */
# include <string> /* std::string */
# include <vector> /* std::vector */
extern R"(C++)" auto Main( const std::vector<std::string> &Arguments ) noexcept( false ) -> void
{
for( const auto &Argument : Arguments )
static_cast<void>( std::cout << R"(- ")" + Argument + R"(")" << std::endl );
return;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment