How to concatenate twice with the C preprocessor and expand a macro as in “arg ## _ ## MACRO”?

How to concatenate twice with the C preprocessor and expand a macro as in “arg ## _ ## MACRO”?

I am trying to write a program where the names of some functions are dependent on the value of a certain macro variable with a macro like this:#define VARIABLE 3#define NAME(fun) fun ## _ ## VARIABLEint NAME(some_function)(int a);Unfortunat

Read whole ASCII file into C++ std::string [duplicate]

Read whole ASCII file into C++ std::string [duplicate]

This question already has an answer here: What is the best way to read an entire file into a std::string in C++? 11 answers I need to read a whole file

When is .then(success, fail) considered an antipattern for promises?

When is .then(success, fail) considered an antipattern for promises?

I had a look at the bluebird promise FAQ, in which it mentions that .then(success, fail) is an antipattern. I don't quite understand its explanation as for the try and catch. What's wrong with this the following?some_promise_call().then(fun

Get selected element's outer HTML

Get selected element's outer HTML

I'm trying to get the HTML of a selected object with jQuery. I am aware of the .html() function; the issue is that I need the HTML including the selected object (a table row in this case, where .html() only returns the cells inside the row

Converting ISO 8601-compliant String to java.util.Date

Converting ISO 8601-compliant String to java.util.Date

I am trying to convert an ISO 8601 formatted String to a java.util.Date. I found the pattern "yyyy-MM-dd'T'HH:mm:ssZ" to be ISO8601-compliant if used with a Locale (compare sample).However, using the java.text.SimpleDateFormat, I cannot con

Flatten (an irregular) list of lists

Flatten (an irregular) list of lists

Yes, I know this subject has been covered before (here, here, here, here), but as far as I know, all solutions, except for one, fail on a list like this:L = [[[1, 2, 3], [4, 5]], 6]Where the desired output is[1, 2, 3, 4, 5, 6]Or perhaps eve

What is the canonical way to check for errors using the CUDA runtime API?

What is the canonical way to check for errors using the CUDA runtime API?

Looking through the answers and comments on CUDA questions, and in the CUDA tag wiki, I see it is often suggested that the return status of every API call should checked for errors. The API documentation contains functions like cudaGetLastE

&&= and ||= operators [duplicate]

&&= and ||= operators [duplicate]

Possible Duplicates: Why doesnt Java have compound assignment versions of the conditional-and and conditional-or operators? (&&=, ||=) Why does a “&&=” Operator not exist? Today at work I wrote the following LOC (the real ide

How do I fill a va_list

How do I fill a va_list

If I have a va_list I know how to extract all its elements: void printInts(int n,...){ va_list va; va_start(va, n); for(unsigned int i=0; iSo when I call printInts(3,1,2,3) the va_list get filled of all the parameters.But how do I

sed: -i may not be used with stdin on Mac OS X

sed: -i may not be used with stdin on Mac OS X

I am using a bison parser in my project. When I run the following command:sed -i y.tab.c -e "s/ __attribute__ ((__unused__))$/# ifndef __cplusplus\n __attribute__ ((__unused__));\n# endif/"I get this errorsed: -i may not be used with stdi

How can I call a Perl package I define in the same file?

How can I call a Perl package I define in the same file?

I need to define some modules and use them all in the same file. No, I can't change the requirement.I would like to do something like the following:{ package FooObj; sub new { ... } sub add_data { ... }}{ package BarObj; use

Why does a perfect forwarding function have to be templated?

Why does a perfect forwarding function have to be templated?

Why is the following code valid:templatevoid foo(T1 &&arg) { bar(std::forward(arg)); }std::string str = "Hello World";foo(str); // Valid even though str is an lvaluefoo(std::string("Hello World")); // Valid because literal is rvalueBut not:

Python: finding lowest integer

Python: finding lowest integer

I have the following code:l = ['-1.2', '0.0', '1']x = 100.0for i in l: if i The code should find the lowest value in my list (-1.2) but instead when i print 'x' it finds the value is still 100.0Where is my code going wrong? 1:To find

Variable template in template class - unexpected error (possible bug?)

Variable template in template class - unexpected error (possible bug?)

Having:struct Value{ template static constexpr T value{0};};(0)ideonetemplatestruct Something{ void x() { static_assert(TValue::template value == 0, ""); }};int main() { Something{}.x(); return 0; } Does not compile wi

assigning class variable as default value to class method argument

assigning class variable as default value to class method argument

I would like to build a method inside a class with default values arguments taken from this class. In general I do filtering on some data. Inside my class I have a method where normally I pass vector of data. Sometimes I don't have the vect

How to find duplicates in a list?

How to find duplicates in a list?

I have a list of unsorted integers and I want to find those elements which have duplicates.val dup = List(1,1,1,2,3,4,5,5,6,100,101,101,102)I can find the distinct elements of the set with dup.distinct, so I wrote my answer as follows.val d

Check for inf - objective c

Check for inf - objective c

Would anyone know the method for testing whether a double (or integer) is infinity, for example when 1/0 operation is performed?isfinite(n) does not seem to work. 1:You may check if(d == INFINITY) {}or if(d > DBL_MAX) {}INFINITY is a con

How to invoke MSBuild from PowerShell using & operator?

How to invoke MSBuild from PowerShell using & operator?

I've just tested this on PowerShell v1.0. Setup is as follows: Id CommandLine -- ----------- 1 $msbuild = "C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe" 4 $a = "C:\some\project\or\other\src\Solution.sln /target:Clean /target:Build

Java generics, Unbound wildcards  vs

Java generics, Unbound wildcards vs

I've read a few topics which cover certain questions about generics, such as their relationship with raw types. But I'd like an additional explanation on a certain line found in the Java SE tutorial on unbound generics .According to a sent

How to convert records including 'include' associations to JSON

How to convert records including 'include' associations to JSON

If I do something like:result = Appointment.find( :all, :include => :staff )logger.debug { result.inspect }then it only prints out the Appointment data, and not the associated staff data.If I do result[0].staff.inpsect then I get the staff

ImageIO.write bmp does not work

ImageIO.write bmp does not work

I'm trying to save an image in bmp format, but it doesn't create any file.If I use "png" instead, everything works fine.Any ideas?//This works fine:ImageIO.write(bi, "png", new File("D:\\MyImage.png"));//This does not work:ImageIO.write(bi,

How to force scrapy to crawl duplicate url?

How to force scrapy to crawl duplicate url?

I am learning Scrapy a web crawling framework.by default it does not crawl duplicate urls or urls which scrapy have already crawled. How to make Scrapy to crawl duplicate urls or urls which have already crawled?I tried to find out on inter

Haskell interact function

Haskell interact function

I’m new to Haskell and have a problem with interact function. This is my sample program:main :: IO ()main = interact inputLengthinputLength :: String -> StringinputLength input = show $ length inputIt compiles but when running doesn’t print

Mixing nested type parameters and wildcards in Java

Mixing nested type parameters and wildcards in Java

Why does trying to compilepublic class GenericsFail { public static void main(String[] args) { accept(new HashMap>()); } public static void accept(Map> multiMap) {}}give the errorGenericsFail.java:7: error: method accept in

Git alias on current branch

Git alias on current branch

I'd like to improve my current aliases, most of them work over a branch.Is there a way to refer to the current branch in a git alias so I don't need to pass it each time?like this one:git config alias.po "push origin"is use it like that:git