вчера мне помог хороший человек Chorkov
посидев над его примером кода
удалось сделать так чтоб работал и с zero length
или мне кажется ? вообщем проверьте у себя
#include <iostream>
#include <typeinfo>
#include <boost/preprocessor/array/elem.hpp>
#include <boost/preprocessor/enum.hpp>
#include <boost/typeof/typeof.hpp>
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
#define цой_жив(...) , ## __VA_ARGS__
#define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define REPEAT_PARAMS(...) (__VA_ARGS__)
#define COUNT_PARMS(...) \
COUNT_PARMS2 REPEAT_PARAMS(цой_жив(__VA_ARGS__) 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define test(...) COUNT_PARMS(__VA_ARGS__)
int main()
{
printf("%d\n", test());
printf("%d\n", test(1));
printf("%d\n", test(2,2));
printf("%d\n", test(3,3,3));
ExitProcess(0);
}
[In theory there is no difference between theory and practice. In
practice there is.]
[Даю очевидные ответы на риторические вопросы]
Здравствуйте, jyuyjiyuijyu, Вы писали:
J>вчера мне помог хороший человек Chorkov
J>посидев над его примером кода
J>удалось сделать так чтоб работал и с zero length
J>или мне кажется ? вообщем проверьте у себя
Ради интереса поковырялся:
#include <stdio.h>
#include <stdarg.h>
#ifdef _MSC_VER
#define _En(...) (__VA_ARGS__)
#define _E1(x) x
#define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define COUNT_PARMS(...) _E1(COUNT_PARMS2)_En(0 __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#else
#define COUNT_PARMS2(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _, ...) _
#define COUNT_PARMS(...) COUNT_PARMS2(0 __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#endif
void print_strings2(const char* va_arg_str,int count,...)
{
if(va_arg_str[0] == '\0') { printf("!!!\n"); return; }
va_list v;
va_start(v, count);
for(int i = 0; i < count; i++)
{
/* Grab next parameter + print it */
const char *s = va_arg(v, const char *);
printf("%s", s);
}
va_end(v);
}
#ifdef _MSC_VER
#define print_strings(...) print_strings2("" #__VA_ARGS__, COUNT_PARMS(__VA_ARGS__), __VA_ARGS__)
#else
#define print_strings(...) print_strings2("" #__VA_ARGS__, COUNT_PARMS(__VA_ARGS__), __VA_ARGS__ "")
#endif
int main()
{
print_strings();
print_strings("1\n");
print_strings("1","2\n");
return 0;
}
Работает в msvc2005sp1 и g++ v4.4.0
[In theory there is no difference between theory and practice. In
practice there is.]
[Даю очевидные ответы на риторические вопросы]
[In theory there is no difference between theory and practice. In
practice there is.]
[Даю очевидные ответы на риторические вопросы]