Safe conversion from __int64 to size_t

I am working on Windows OS with Visual Studio 2017, and I obtained the following function to determine the size of a file from one of SO's answers: __int64 FileSize(const char *filename) { HANDLE hFile = CreateFile(filename, GENERIC_READ, ...
more »

2017-10-04 14:10 (4) Answers

How to #import inside a #define

I'm working on an Objective-C wrapper around a C++ library, whose source I neither control nor modify. The headers I import trigger various compiler warnings, so I've started to do the following: #pragma clang diagnostic push #pragma clang diagnosti...
more »

2017-10-03 23:10 (1) Answers

String Validation

How do you validate a string to check if it has only uppercase letters? And how do you check if it has both uppercase and lowercase letters? cout << "Enter state name or state abbr:" << " " << endl; cin >> st; if ((st == sta...
more »

2017-10-02 09:10 (1) Answers

Heap sort is not used in C++ library

Since heap sort has time complexity of O(nlogn) in all scenarios i.e. best case,average case and worst case. While quick sort has time complexity of O(n2) in worst case. Then despite having less complexity in worst case, why heap sort is not impleme...
more »

2017-10-01 16:10 (2) Answers

Convert C++ function to MIPS

If you are given: calc (int b) { return b - 2; } How would it be converted to MIPS? I've considered the following: addi $v0, $a0, -2 jr $ra *********************** jr $ra addi $v0, $a0, -2 *********************** addi $v0, $a0, 2 jr $ra ******...
more »

2017-09-30 08:09 (1) Answers

What is a function client?

I just read in "C++ How to Program" 10th Edition that "if you change the definition of an inline function, you must recompile all of that function's clients." What is a client? I've been poring over the Internet and all I could find were web pages ex...
more »

2017-09-30 02:09 (2) Answers

Poor performance of C++ function in Cython

I have this C++ function, which I can call from Python with the code below. The performance is only half compared to running pure C++. Is there a way to get their performance at the same level? I compile both codes with -Ofast -march=native flags. I ...
more »

2017-09-29 22:09 (1) Answers

Embed python / numpy in C++

I am trying to use python 3 (with numpy) in my C++ application. This entails sending a C++ array to python, performing calculations and then retrieving the result in C++. To do this I based myself on the code that was discussed here: https://coderevi...
more »

2017-09-29 18:09 (1) Answers

Variadic template as parameters to std::function

I want to build a structure that allow me to call member functions with an undefined number of parameters. For now I wrote something like this template<typename Class, typename Return, typename ... Args> struct Caller { private: std::funct...
more »

2017-09-29 15:09 (2) Answers