Skip to content

Instantly share code, notes, and snippets.

@nlyan2025
Created April 22, 2020 16:22
Show Gist options
  • Select an option

  • Save nlyan2025/33755c59bf31c3f3b986b5392d54fba6 to your computer and use it in GitHub Desktop.

Select an option

Save nlyan2025/33755c59bf31c3f3b986b5392d54fba6 to your computer and use it in GitHub Desktop.

Revisions

  1. @nlyan nlyan created this gist Apr 22, 2020.
    20 changes: 20 additions & 0 deletions commas.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #include <boost/preprocessor.hpp>

    // the magic

    #define MAGIC_PLACEHOLDER_FILLER_0(X, Y) ((X, Y)) MAGIC_PLACEHOLDER_FILLER_1
    #define MAGIC_PLACEHOLDER_FILLER_1(X, Y) ((X, Y)) MAGIC_PLACEHOLDER_FILLER_0
    #define MAGIC_PLACEHOLDER_FILLER_0_END
    #define MAGIC_PLACEHOLDER_FILLER_1_END

    // example usage

    #define MAGIC2(Z, N, ARGS) \
    { BOOST_PP_REMOVE_PARENS (BOOST_PP_SEQ_ELEM (N, ARGS)) }

    #define MAGIC(EXPRS) \
    BOOST_PP_ENUM (BOOST_PP_SEQ_SIZE (BOOST_PP_VARIADIC_SEQ_TO_SEQ (EXPRS)), \
    MAGIC2, \
    BOOST_PP_CAT (MAGIC_PLACEHOLDER_FILLER_0 EXPRS, _END))

    MAGIC ((42, "security") (101, "price") (102, "volume"))