Advertisement
sophtwhere

SW+Variadic.h

Nov 20th, 2013
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  SW+Variadic.h
  3. //  Sophtwhere
  4. //
  5. //  Created by Jonathan Annett on 17/12/11.
  6. //  Copyright (c) 2011 Sophtwhere. All rights reserved.
  7. //
  8.  
  9. /*
  10.  
  11.  .  This header contains macros that are core to the
  12.  .  Sophtwhere Objective C extension approach.
  13.  .
  14.  .  They are used for counting macro arguments and automatic selection of
  15.  .  sub macros based on the number of arguments being used.  
  16.  .
  17.  .  Original source: these macros were adapated from information gleaned from
  18.  .  the following web posts, with the second url being the most likely candidate
  19.  .  as the original author.
  20.  
  21.  http://stackoverflow.com/questions/5365440/variadic-macro-trick
  22.  
  23.  http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/
  24.  
  25.  
  26.  */
  27.  
  28. #define VA_NARGS_IMPL(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, N, ...) N
  29. #define VA_NARGS(...) VA_NARGS_IMPL(X,##__VA_ARGS__, 11, 10,9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
  30. #define VARARG_IMPL2(base, count, ...) base##count(__VA_ARGS__)
  31. #define VARARG_IMPL(base, count, ...) VARARG_IMPL2(base, count, __VA_ARGS__)
  32. #define VARARG(base, ...) VARARG_IMPL(base, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
  33.  
  34.  
  35.  
  36. #define __variadicName(...) VARARG(__variadicName_, __VA_ARGS__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement