« first day (876 days earlier)      last day (1977 days later) » 

6:04 AM
Good morning all
I am new in C/C++. I have few .cpp and .h files I have to use those files into my Android studio but getting the error for #include "BoostLog.h" so how can I download that header so that I can include it in my IDE?
 
I don't really understand what you are trying to do is this your code? did you wrote these files?
 
@ma1169 Actually I have to port C++ code into Android and I have few .cpp and .h files so when I am trying to add them getting some errors like can not find "BoostLog.h" so I want to know how can o download this header?
i didn't write
Is it dynamic header like we need to install any library or something else?
I don't have any Ideas about C++.
 
look anything written like this #include "xxx.h" are custom made header file, you need to find it from the place you got this files from
 
I think boost-159 library was using inC++ code but BoostLog.h is not in code
boost-159 was for window app
might be boost-159 is used for BoostLog.h?
 
so this will be a third party code, right? is this what you mean https://www.boost.org/
if so then you might want to download it from there
 
6:20 AM
@ma1169 Yes, I asked to client and he said he installed boost-159.
but not sure will BoostLog.h come inside boost lib or not
 
to answer this -> Is it dynamic header like we need to install any library or something else?
.h is a header file so you should have .header file called BoostLog.h in your project
i am trying to download it to see whether it contain this file or not
 
@ma1169 OKay thanks
 
6:41 AM
I cannot find a file named boostlog.h in boost library, so i'll assume this might be a part of another library. again you need to check where did you get this from and since you have to port this code so you should have this header file in your base source code?!!!
 
@ma1169 Yes, you are a right problem is that client made that app from another developer now we have to port that code
and he don't know about this
:(
 
yep your client should contact his ex developer about this or to start a new project
 
 
2 hours later…
Sam
8:22 AM
How should i set up complex objects that I need to inject for unit testing? Should I just have some factory methods in my unit testing classes?
 
 
3 hours later…
11:09 AM
Is it possible to have a general purpose `max` function that is variadic and also supports any type of arguments?

For example,
max(15.24, 6) => 15.24
max(15.24, 206llu) => 206llu
I thought of using a macro for this, but then they aren't recursive
also overloaded template functions were good until I realized that I can have only one type of return value
T max(T a, U b){
     return (a > b) ? a : b;
}
so if U is a larger datatype as compared to T, and if b happens to be the larger number (a > b false), then b unfortunately gets downcast to T type and information is lost
 
about this: https://stackoverflow.com/a/41141602/855869
> Or, change your project properties to be a command line application.

apparently I made that same mistake. Where is in Visual studio 2017 the option to switch to command line application?
So far I have only found the option "configuration type -> application (.exe)" and I can select .dll/.lib or utility, but I see no references to command line.

[also, should I ask on one of the main sites?]
 
nwp
@GaurangTandon Just use auto. The ?: already returns the common type of T and U so you don't have to.
If you wanted to do it by hand there is std::common_type.
 
hey thanks @nwp
 
nwp
@Federico It is under Linker->System->SubSystem.
 
but it seems even before that I have another problem
template <typename T, typename U>
auto ma(T a, U b)
{
    return a > b ? a : b;
}

template <typename T, typename... Args, typename U>
auto ma(T a, Args... args)
{
    U b = ma(args...);
    return ma(a, b);
}
compiler complains that "note: couldn't deduce template parameter ā€˜Uā€™" when I call ma with three arguments
what default value do I assign to U?
 
nwp
11:20 AM
That makes sense right? No way to figure out what U is from looking at the declaration.
You probably want auto instead of U again.
 
@nwp just tested following this stackoverflow.com/a/8532797/855869 , still same linker error :(
I also tried rebuilding, no dice
 
nwp
By linker error you mean undefined reference to _WinMain@16, right?
 
yes
LNK2019
> LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
 
nwp
Are you sure you set it to "Console"?
 
in the option that you suggested? yes. I selected "console" and saved
 
11:26 AM
woah many thanks @nwp, works perfectly. I used to think that C++ auto keyword evaluates at compile time...didn't know it was runtime allocated
this is the test code
#include <iostream>
#include <cmath>

using namespace std;

template <typename T, typename U>
auto ma(T a, U b)
{
    return a > b ? a : b;
}

template <typename T, typename... Args>
auto ma(T a, Args... args)
{
    auto b = ma(args...);
    return ma(a, b);
}

int main()
{
    cout << ma(5, 6) << endl;
    cout << ma(5, 6.12) << endl;
    cout << ma(5, 6.12, 7lu) << endl;
    cout << fixed << ma(5123456789050000llu, 6123456789512345.987l, 6123456789021345llu);
}
works perfectly :)
 
nwp
@Federico I don't know, it's supposed to work. Maybe try another clean or something. If everything fails create a new console project and copy the files over.
@GaurangTandon It does the type-deduction at compile-time, just like typename T.
 
@nwp then how does it know at compile time which of a or b is bigger?
 
nwp
It doesn't. But it does know what type ma returns.
 
nwp
You might be missing that the expression condition ? a : b returns the common type of a and b, so true ? 42 : 3.14 returns a double with value 42.0.
 
11:32 AM
@nwp oh...i used to think it returns typeof a if a was greater or typeof b is b was greater
now i get how @milleniumbug's example works
and now if I try to fix it it gives loads of errors :(
template <typename T, typename U>
auto ma(T a, U b)
{
    if(a > b) return a;
    else return b;
}
there is no way around this I guess?
 
nwp
Not really. C++ has to know the type at compile-time, otherwise compiling becomes really difficult. There is some support for dynamic types in the form of inheritance and std::any/std::variant, but I don't think those are appropriate here.
The common_type approach just fails if you have something like long long int and long long unsigned int because there is no type that can hold all values of both.
The best you can do is choose better common types than ?: does.
 
hmm
@nwp how do i get to choose the common types?
 
nwp
You can closely look at std::common_type and see if that is sufficient. Otherwise write your own.
A good test is probably if std::common_type_t<unsigned long long, long long> exists. If it doesn't it's probably as good as it gets.
 
hmm, ok, i'll have a look at it...
thanks for the help btw, i really appreciate it :)
 
nwp
Maybe add ma(std::string{"Hello"}, std::string{"World"}); to the test cases, that might break with common_type.
 
11:48 AM
hmm i didn't even know in-built std::max works with std::string
 
@nwp solution: create project in VS2013 Ultimate, because apparently VS2017 does not let me create a console application, but I can open and modify it :/
 
 
3 hours later…
3:15 PM
Hey, while list is stored individually on memory, vector is stored sequentially. What about map?
 
nwp
The complexity guarantees don't allow it to use a vector as the backing memory.
In theory it could allocate batches of nodes. I have not heard of any implementation actually doing that.
 
does that mean map is likely implemented on contiguous memory?
 
nwp
No, that's the opposite of what I said.
 
so in reality maps don't actually allocate memory for values, just enough to store information where the values are found?
 
nwp
In reality std::map is likely to have something like a struct Node { Key key; Value value; Node *left, *right; }; which is individually newed and deleted.
 
3:27 PM
Thank you
So, positiom of its elements on memory are fix? I have to access elements via pointer so I make sure the position on memory will not change.
*have to
 
4:23 PM
Hello,
does anyone know any website that you found useful for practicing data structure/algorithm by problem solving?
 
 
3 hours later…
nwp
7:08 PM
@Findus Right, the elements will not be implicitly relocated.
 

« first day (876 days earlier)      last day (1977 days later) »