variadic-functions

How can I create a Stream<String[]> with only one element with Stream.of?

你离开我真会死。 提交于 2019-12-22 01:33:47
问题 Using Stream.of to create generic streams is very convenient, but what if I want to create a Stream<String[]> of only one element? Let’s say I have: String[] tropicalFruits = new String[] {"pineapple", "banana", "mango"}; String[] fruits = new String[] {"melon", "peach", "apple"}; Then Stream.of(tropicalFruits, fruits) produces a Stream<String[]> of two elements. How can I achieve the same for a stream of a single element? If I try: Stream<String[]> fruityStream = Stream.of(tropicalFruits); I

How to expose a c++ function taking variable arguments in boost python

偶尔善良 提交于 2019-12-22 01:29:07
问题 I have a c++ function taking variable number of arguments. char const* Fun(int num, ...) { ....//does some processing on the arguments passed } Boost Python code for exposing this function is written as, using namespace boost::python; BOOST_PYTHON_MODULE( lib_boost ) { def( "Fun", Fun ); } while compiling this code gives the below error In file included from /boost_1_42_0/boost/python/data_members.hpp:15, from /boost_1_42_0/boost/python/class.hpp:17, from /boost_1_42_0/boost/python.hpp:18,

multiple inputs by user dynamically at runtime

混江龙づ霸主 提交于 2019-12-22 00:50:03
问题 How can we take multiple number of integer inputs by user choice in c in runtime. Here the first line of the input is the number of test cases . Then I am calculating the sum of the input numbers in this case. The test case : Input 3 1 6 7 2 7 3 4 2 1 Output: 14 16 3 Can we modify scanf() in this way so it can process this dynamic inputs. I can't take the line as a string input and then split them into numbers. Can we use the space and \n both to decide the numbers as we do to take strings as

Sequencing among a variadic expansion

混江龙づ霸主 提交于 2019-12-21 15:42:33
问题 For this non-variadic example: int Func1(); double Func2(); void MyFunc( int, double ); int main() { MyFunc( Func1(), Func2() ); //... } it's not specified whether Func1() or Func2() is computed first, just that both must be done before MyFunc() is called. How does this sequencing work with the expansion of variadic arguments? template < typename Func, typename ...Args > void MyFunc2( Func &&f, Args&& ...a ) { int b[] = { f( std::forward<Args>(a) )... }; //... } Let's say that f is a function

Sequencing among a variadic expansion

亡梦爱人 提交于 2019-12-21 15:39:28
问题 For this non-variadic example: int Func1(); double Func2(); void MyFunc( int, double ); int main() { MyFunc( Func1(), Func2() ); //... } it's not specified whether Func1() or Func2() is computed first, just that both must be done before MyFunc() is called. How does this sequencing work with the expansion of variadic arguments? template < typename Func, typename ...Args > void MyFunc2( Func &&f, Args&& ...a ) { int b[] = { f( std::forward<Args>(a) )... }; //... } Let's say that f is a function

Implementation of __builtin_va_start(v,l)

☆樱花仙子☆ 提交于 2019-12-21 12:14:40
问题 Going down the rabbit hole of variadic macros in glibc, I’ve reached /usr/lib/gcc/x86_64-linux-gnu/4.8.2/include/stdarg.h where, for example, the va_start macro is defined as: #define va_start(v,l) __builtin_va_start(v,l) But I’ve been trying to look for the actual implementation of __builtin_va_start(v,l) without success. I’ve googled and grepped for it, and the furthest I’ve gotten to is Microsoft’s implementation for Visual Studio, which I suppose isn’t radically different. Does anybody

What is an apparently correct example of Java code causing heap pollution?

梦想的初衷 提交于 2019-12-21 07:23:12
问题 I'm trying to decide what to do every time I get a Java heap pollution warning when using parameterized varargs such as in public static <T> LinkedList<T> list(T... elements) { ... } It seems to me that if I am confident not to be using some weird casts in my methods, I should just use @SafeVarargs and move on. But is this correct, or do I need to be more careful? Is there apparently correct code that is actually not safe when using parameterized varargs? Reading about the subject, I notice

Abstract method with variable list of arguments

余生长醉 提交于 2019-12-21 06:58:42
问题 I haven't quite found an elegant way to solve this issue. I have an abstract class that several other classes are inheriting with an abstract method that can contain anywhere from zero to 4-5 arguments of varying types. public abstract class Item { public abstract void use(); } For instance, I have a Book class that inherits this and takes no arguments when overriding use(), I have a Key class that inherits and takes a String and a Queue as arguments when overriding, etc... I've tried using

C/C++ va_list not returning arguments properly

前提是你 提交于 2019-12-21 05:28:09
问题 I have a problem with using va_list. The below code works for an int: main() { int f1=1; float** m = function(n,f1); } float** function(int n,...) { va_list mem_list; va_start(mem_list, n); for (int i=0;i<n;i++) { for (int j=0;j<n;j++) { //m[i][j]=va_arg(mem_list,float); int f = va_arg(mem_list,int); printf("%i \n",f); } } va_end(mem_list); return NULL; } However when I change to a float i.e. float f1=1.0; float f = va_arg(mem_list,float); printf("%f \n",f); It does not return the right value

Visual studio __VA_ARGS__ issue

Deadly 提交于 2019-12-20 15:34:04
问题 I run cl /P test.cpp, the file and result is as following. test.cpp #define FiltedLog( ...) \ if (logDetail) \ MP_LOG(LOG_INFO, __VA_ARGS__); #define MP_LOG(level,fmt,...) \ BOOAT::LOG("MP", level, fmt, ##__VA_ARGS__) #define LOG(tag,level,fmt,...) \ Log::log(tag, level, "%s: " fmt, __PRETTY_FUNCTION__, ##__VA_ARGS__) int main () { FiltedLog ( "abc", 1, 2); } Cl /P test.cpp : #line 1 "test.cpp" int main () { if (logDetail) BOOAT::Log::log("MP", LOG_INFO, "%s: " "abc", 1, 2, __PRETTY_FUNCTION_