einpoklum

0

votes
1

answer
14

views

Will -Wpedantic do anything when compiling with a non-extension -std?

If I compile my C or C++ code with GCC, using -std=c99 or -std=c++11 or some other proper ISO standard rather than a GNU extension - will -Wpedantic issue more warnings that I would usually get? e.g. With -W, -Wall or -Wall -Wextra?
einpoklum
1

votes
3

answer
409

views

The “no known conversion” from const char* to an iterator error - another take

I'm doing the following: using namespace boost; const char* line = // ... size_t line_length = // ... // ... tokenizer line_tokenizer( line, line + line_length, escaped_list_separator('\\', ',', '\"')); Expecting to use the boost::tokenizer constructor tokenizer(Iterator first, Iterator last, const...
einpoklum
1

votes
3

answer
156

views

Unexpected result from #cmakedefine substitution

Suppose that in my CMakeLists.txt I have: check_function_exists(getopt HAVE_GETOPT) configure_file(config.h.in config.h @ONLY) and in config.h.in I have: #cmakedefine HAVE_GETOPT @[email protected] #cmakedefine STDLIB_HAS_GETOPT @[email protected] I expect to see #define HAVE_GETOPT 1 #define STDLIB_HAS_GETOP...
einpoklum
1

votes
1

answer
612

views

Is there a CUDA equivalent of perror()?

Is there a CUDA function for printing both a caller-supplied error message, and an error message describing the current cudaStatus (or a caller-supplied cudaStatus), a-la-perror()?
einpoklum
1

votes
3

answer
2.4k

views

In C++, how can I get the current thread's call stack?

I'm writing this error handler for some code I'm working in, in C++. I would like to be able to make some sort of reference to whatever I have on the stack, without it being explicitly passed to me. Specifically, let's say I want to print the names of the functions on the call stack, in order. This...
einpoklum
1

votes
2

answer
1.6k

views

How can I download an Eclipse plugin as a zip archive using an update site?

I have Eclipse installed on a box which is off the Internet. I found this package I want to install, but I only have an update URL for it, not an archive file I can copy to the disconnected machine and put in its Eclipse' dropins/ folder like with some other extensions. On a machine connected to t...
einpoklum
1

votes
2

answer
465

views

Does cmake ignore .hpp file changes?

I have this C++ project I'm building with cmake. It seems like changes I make to .hpp files don't result in a rebuild of the .o file of the .cpp including the .hpp . Is that really the case or am I getting something wrong? Also, how can I tell cmake to notice `#include "something.hpp" dependencies?
einpoklum
1

votes
2

answer
992

views

idiomatic way to sanitize a string for printing to a terminal?

I have this string in memory, which I want to print to a terminal or a log file - without getting garbage/non-printable characters which, well, cramp my style. So, instead of my_output_stream
einpoklum
1

votes
3

answer
66

views

How can I implement a function for invoking any (arbitrary) function with its (arbitrary) arguments?

I would like to have the following: void foo( /* something representing a function f */, /* arguments a1, a2, etc. in some form */ ) { /* magic - invoke f(a1, a2, etc.)*/ } /* ... */ void bar(float f, char* s); void baz(int i); /* etc. */ int main() { /* ... */ foo(bar, SomeKindOfTransformationOrN...
einpoklum
1

votes
1

answer
487

views

How can I obtain timing values from the output of nvprof or of NVidia Visual Profiler?

I'm using nvprof to profile something (which includes both CPU work and GPU work, i.e. I use nvprof markers etc.), and I get binary files which nvprof produces. I can import these into NVVP (NVidia Visual Profiler; Linux version), and with a little effort also save that out to an XML. However... t...
einpoklum
1

votes
2

answer
168

views

How can I tell whether it's safe/necessary to cudaFree() or not?

I've allocated some GPU global memory with cudaMalloc(), say, in the constructor of some class. Now it's time to destruct the instance I've constructed, and I have my instance's data pointer. The thing is, I'm worried maybe some mischievous code elsewhere has called cudaDeviceReset(), after which my...
einpoklum
1

votes
1

answer
764

views

Undefined reference when linking with Boost using g++-4.9 on a g++-5-ish distribution

I've written the following groundbreaking application: #include int main(int argc, char** argv) { boost::program_options::options_description generic_options("foo"); return 0; } I am trying to build this on Debian Stretch, on which the default compiler is GCC 5.3.1-5, and the installed version of B...
einpoklum
1

votes
1

answer
109

views

Reference lost on forwarding (and no auto-conversion to save me) - why?

I'm writing a Factory for producing instances of subclasses of a base class using their name, and using this (templated) factory with my class Foo. Never mind the entire code, but essentially, the factory has a map from string to functions creating instances; and a template parameter controls which...
einpoklum
-1

votes
1

answer
57

views

How can I check whether a class has a templated invoke operator without knowing its return type? [duplicate]

This question already has an answer here: Find out whether a C++ object is callable 6 answers I have a templated function template auto foo(F f) { ... } Within this function, I want to sort-invoke F: I want to call F.template operator()(), with no arguments - but only if it exists. Otherwise I'm r...
einpoklum
2

votes
2

answer
63

views

Simplest way to “correct” an accidental use of mv instead of an hg mv?

I have a tracked foo. Now, since I'm absent-minded, I've run: mv foo bar now, when I do hg st, I get: ! foo ? bar I want to fix this retroactively - as though I'd done an hg mv foo bar. Now, I could write a bash script which does that for me - but is there something better/simpler/smarter I could do...
einpoklum
2

votes
1

answer
171

views

How can I dump all NVCC preprocessor defines?

I want to achieve the same effect as gcc -dM -E - < /dev/null (as described here) - but for nvcc. That is, I want to dump all of nvcc's preprocessor defines. Alas, nvcc doesn not support -dM. What do I do instead?
einpoklum
3

votes
2

answer
110

views

What namespace to use for code that “augments std”?

Sometimes you find yourself writing some bits of header code which could really have fit nicely into the C++ standard library. Just as an example: a disable_if template, doing the converse of std::enable_if. I don't want to just put it in the global namespace. But what's the convention? Should I......
einpoklum
3

votes
2

answer
692

views

Determining which gencode (compute_, arch_) values I need for nvcc - within CMake

I'm using CMake as a build system for my code, which involves CUDA. I was thinking of automating the task of deciding which compute_XX and arch_XX I need to to pass to my nvcc in order to compile for the GPU(s) on my current machine. Is there a way to do this: With the NVIDIA GPU deployment kit? Wi...
einpoklum
5

votes
1

answer
98

views

Why does it help to assign a const& scalar value to a const before a loop?

In GCC 5.4.0's stl_algobase.h we have: template inline typename __gnu_cxx::__enable_if::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { for (; __first != __last; ++__first) *__first = __value; } template inline typename __gnu_cxx::__enable_if:...
einpoklum
1

votes
2

answer
119

views

Can I `__restrict__ this` somehow?

I've been watching Mike Acton's talk on Data-oriented design in C++ in CppCon 2014, and he gives this example: int Foo::Bar(int count) { int value = 0; for (int i = 0; i < count; i++) { if (m_someDataMemberOfFoo) value++ } return value; } And explains how some compilers keep re-reading m_someDataMem...
einpoklum
1

votes
2

answer
516

views

Why and in what sense is pthread_t an opaque type?

Posts here on SO suggest that pthread_t is an opaque type, not a number, certainly not a thread index, that you shouldn't directly compare pthread_t's, etc. etc. Questions: Why? Is there really the intent to support systems with no numeric IDs for threads? When the pthread_t implementation is simply...
einpoklum
1

votes
2

answer
126

views

Pitfalls of “making” unique_ptr<T> implicitly convertible to T*?

I just read Add implicit conversion from unique_ptr to T* which focuses on the how-to-do-it part, not on should-I-do-it. I'm also not asking whether or not you think it's a good idea, but I am asking for concrete pitfalls I might stuble onto, or into, if I subclass unique_ptr to add the functionalit...
einpoklum
17

votes
6

answer
2.5k

views

How can I use C++11 variadic templates to define a vector-of-tuples backed by a tuple-of-vectors?

Suppose I have a bunch of vectors: vector v1; vector v2; vector v3; all of the same length. Now, for every index i, I would like to be able to treat (v1[i], v2[i], v3[i]) as a tuple, and maybe pass it around. In fact, I want to have a a vector-of-tuples rather than a tuple-of-vectors, using which I...
einpoklum
18

votes
1

answer
391

views

Is there really no version of realloc() supporting alignment?

There exist several aligned versions of the venerable malloc(), e.g.: #include int posix_memalign(void **memptr, size_t alignment, size_t size); void *aligned_alloc(size_t alignment, size_t size); #include void *memalign(size_t alignment, size_t size); (originating in POSIX, glibc and Linux libc r...
einpoklum
3

votes
1

answer
395

views

When should I prefer write-combined CUDA-allocated mapped host memory?

the cudaHostAlloc() API call has, among others, the flags: cudaHostAllocMapped: Maps the allocation into the CUDA address space. The device pointer to the memory may be obtained by calling cudaHostGetDevicePointer(). cudaHostAllocWriteCombined: Allocates the memory as write-combined (WC). WC memory...
einpoklum
6

votes
1

answer
1.7k

views

How do I know whether bash kill will use a pid or a jobspec?

From the fine manual page: kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ... kill -l [sigspec | exit_status] Send the signal named by sigspec or signum to the processes named by pid or jobspec. sigspec is etc. etc.... So what decides whether kill 1 kills the init process or jobspec...
einpoklum
5

votes
4

answer
211

views

Having a template parameter depend on a parameter list

I have defined the class template struct Bar { using inner_type = /* whatever */; }; Now, I need to define a templated class Foo whose template parameters are some parameter pack, and a value of type Bar::inner_type instantiated for that parameter pack. Unfortunately I can't seem to be able to do i...
einpoklum
5

votes
1

answer
214

views

WIll Boost have a version with a modern-C++ “cutoff”?

With C++17 now published, even more of Boost's libraries are now covered by the standard library: optional, variant, any, ASIO (in the Networking TS), coroutines (in a TS) and more. This, in addition to the gobs and gobs of Boost stuff already in the standard, see this answer. I realize that some o...
einpoklum
19

votes
7

answer
14.9k

views

How to prevent Eclipse formatter from messing up text-bulleted comments?

I have (Java) comments such as: /* * The quick brown fox jumped over the lazy dog. * * * Notes: * - The quick brown fox jumped over the lazy dog. The quick brown fox * jumped over the lazy dog. The quick brown fox jumped over the lazy * dog. * - The second quick brown fox jumped over the lazy d...
einpoklum
19

votes
7

answer
37.6k

views

How can I list the files in a zip archive without decompressing it?

How can I get the equivalent of an ls of a .zip file (not gzip), without decompressing it, from the command shell? That is, how can I list the different files compressed within my .zip archive?
einpoklum
1

votes
2

answer
723

views

Why are there no simple atomic increment, decrement operations in CUDA?

From the CUDA Programming guide: unsigned int atomicInc(unsigned int* address, unsigned int val); reads the 32-bit word old located at the address address in global or shared memory, computes ((old >= val) ? 0 : (old+1)), and stores the result back to memory at the same address. These three operatio...
einpoklum
6

votes
6

answer
962

views

How can a Java program keep track of the maximum actual heap size used during its run?

I'm running a certain Java program, with its -Xmx higher than -Xms, i.e. its heap can grow. The heap size at execution end is (IIRC) not the maximum used during the run. How can I get the current heap size? How can I get the maximum heap size over the course of the run, other than periodically polli...
einpoklum
1

votes
1

answer
123

views

An array-backed vector using allocator override - a bad idea?

I recently started working with C++ again, after I worked with it in days of yore when the STL wasn't as popular. Well, the STL is great, but I need to wrap an array of mine in a vector for utilizing STL goodness - without copying anything. So, I read this SO question: Wrapping dynamic array into ST...
einpoklum
1

votes
3

answer
1.1k

views

C++ equivalent of Java's this.getClass().getSimpleName();

In Java, if I want to use the object class' name I can write: String myString = this.getClass().getSimpleName(); What's the C++ equivalent of this? That is, how can I get a string with the name of the class of *this?
einpoklum
20

votes
2

answer
1.7k

views

Why does std::visit take a variable number of variants?

Trying to get more familiar with C++17, I've just noticed std::visit: template constexpr /*something*/ visit(Visitor&& vis, Variants&&... vars); Why does std::visit not take a single variant, but rather any number of variants? I mean, you can always take some standard library function and have it t...
einpoklum
6

votes
1

answer
7k

views

How can I generate box-and-whisker plots with variable box width, in gnuplot?

I'm trying to visualize a data set I have (in Java, but that doesn't matter much) using gnuplot. I could ask a few different questions about this, but for now: Suppose my data is categorical, and for each category I have quartiles 1,2,3, the min and max, and the total weight of samples in that categ...
einpoklum
5

votes
2

answer
298

views

What happens to Boost libs after their inclusion in C++, other than usage with older-standard code?

I've noticed how in C++11, C++14 and onward, more and more Boost libraries are adopted/incorporated into the actual language standard (or into TS documents, which are likely to end up as part of the standard): Boost.optional, Boost.Any, Boost's threading library, smart pointers, etc. etc. Are these...
einpoklum
2

votes
1

answer
197

views

Is there a proposal to extend the C++ language so as to obviate pimpl?

Sometimes, you want to provide a class declaration, which is not merely an opaque forward declaration but has the public functionality exposed - yet you don't want to commit to your private, or implementation-specific, fields and methods. One solution for this is the pimpl idiom - using a pointer to...
einpoklum
20

votes
4

answer
6.2k

views

Eclipse keeps crunching while “updating rpm packages proposal list”

I've recently installed Eclipse Kepler CDT on a Win7 64 machine. It runs fine (well, sort of), but - it keeps crunching, with the status bar saying Updating RPM packages proposal list Why is this happening and how can I make it stop?
einpoklum

View additional