|
Boost : |
Subject: [boost] [preprocessor] Lists vs. nil-sequences?
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-03-02 09:32:24
Hello all,
I have a curiosity about Boost.Preprocessor: What is the difference
between pp-lists and pp-sequences starting with a NIL element?
PP-Lists can be empty or nil (e.g., have 0 size, etc) while
pp-sequences cannot. However, I could use sequences that always start
with a nil element `(NIL) ...` and write macros that ignore this 1st
element so to handle empty pp-sequences:
#define NILSEQ_SIZE(nilseq) BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(nilseq))
NILSEQ_SIZE( (NIL) ) // 0
NILSEQ_SIZE( (NIL)(a) ) // 1
NILSEQ_SIZE( (NIL)(a)(b) ) // 2
BOOST_PP_LIST_SIZE( BOOST_PP_NIL ) // 0
BOOST_PP_LIST_SIZE( (a, BOOST_PP_NIL) ) // 1
BOOST_PP_LIST_SIZE( (a, (b, BOOST_PP_NIL)) ) // 1
Similarly, I could program NILSEQ_FOR_EACH, NILSEQ_ENUM, etc.
What are the pros and cons of using pp-nil-sequences vs pp-lists given
that both allow for emptiness?
Thank you very much.
-- Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk