« first day (227 days earlier)      last day (2632 days later) » 
00:00 - 15:0015:00 - 00:00

3:00 PM
then strlen(scriptIdentifier.c_str()) will return you the length.
@YashasSamaga it will
 
the strlen is going to kill me
 
you kinda don't have another option unless there is a way to get the length
@YvesHenri the value returned from get doesn't own the object so if the unique_ptr gets destroyed you end up with a dangling pointer
 
@ratchetfreak is it worth doing all that?
I can instead make two copies
I have two resizes and one strlen now
In most cases, the length is going to be less than 20
so std:string might actually copy the string to its SSO array
so in most cases it'll end up coying the data
 
the second resize is just a update of the length and setting a single char to 0 (O(1))
 
it doesn't move the string to its SSO array?
 
3:05 PM
it will only do a second copy for SSO when you do shrink_to_fit
 
if resize value is less than 20?
 
I believe
 
@ratchetfreak I'm aware, but suppose the unique_ptr lives just enough and you have get() calls from all around the world. the unique_ptr is being shared in this situation, therefore behaving like a shared_ptr. no?
the questions is basically the uniqueness of an unique_ptr and its behavior vs a shared_ptr
 
there will only be a single instance of unique_ptr alive, it needs to be passed around by ref or with move semantics
 
I'm not talking about the implementation of unique and shared smart pointers. I'm talking about the true meaning of "unique" and "shared"
 
3:07 PM
shared_ptr can be copied
 
about the implementation (use counts etc)*
you get me?
 
@user8469759 Use std::unique_ptr since the array is clearly owning
 
you can treat a shared_ptr exactly like a unique_ptr and get only minimal overhead
 
@YvesHenri No, I don't
If you need std::shared_ptr you use std::shared_ptr
 
actually, I'm trying to avoid smart pointers. I've used it only once because it was REALLY necessary (github.com/YvesHenri/Delegator for reference)
I'm trying to model some classes and some of them will surely need to use pointers, but Idk which one to use exactly (raw, smart shared, smart unique etc)
 
3:11 PM
how is that different from std::function
 
std::function cant be checked for equality and also is way too slow
not to mention you should avoid using std::binds...
 
std::bind is completely irrelevant to std::function
 
@YvesHenri You can check for equality using std::function.target
 
@milleniumbug not when you need to use member functions
 
Still irrelevant
std::bind returns a function object, lambda is a function object, std::mem_fn returns a function object...
 
3:16 PM
@YashasSamaga by equality I mean the == operator, not how you would compare it yourself. the == operator is needed when using search functions like std::find for example
 
The only common part is that INVOKE, used by std::function can call them all
and also member function pointers and function pointers, and data member pointers...
 
@milleniumbug std::men_fn has been deprecated
 
the == operator for function checks for nullptr only
 
@YvesHenri No
 
but target returns you the address of the function
 
3:18 PM
You're thinking of std::mem_fun
 
What does std::function havning == got to do with a predicate?
 
std::mem_fn is C++11 and newer
Still not deprecated
 
right, try to create an array of std::function and then erase one out. tell me howd you do that (performance-wise as well)
 
swap with back and pop
 
erase a given std::function...
basically, you cant. unless you write some nasty hack
 
3:20 PM
Largest size that can g++ handle (compile)?
 
@Siliproksi size of what?
 
Largest size of what
 
@Siliproksi until the OS stops giving it memory
 
Largest size of file.
C++ Program
Or c
 
the delegator I wrote weights a lot less than a std::function, does not use the weird std::bind, can be easily comparated and a lot faster than a std::function, so why not?
 
3:21 PM
@Siliproksi If you are using some DOS age g++ (DJGPP for example), you are going to hit the 640KB memory limit too soon
@Siliproksi it depends on your host environment
 
@Siliproksi it will try until it hits the OS limits or hardware limits
still, you're asking the wrong question
 
I have a virtual machine and it is Ubuntu. 2 GB of ram.
@milleniumbug What is the prob with the question?
 
large project are split into multiple files
@Siliproksi let's say I give you the answer. What will you do with that information?
 
and if you then change hardware or you start up a memory-hog application which changes the limit
 
@milleniumbug I have 2 arrays each 8 MB, thats why I ask. I dont ask to do philosophy, dont worry.
 
3:29 PM
so you've asked an unrelated question
good job
 
Ah... This stackoverflow. Good Bye...
 
@Siliproksi use std::vector
 
you fell into the XY trap
 
"I have 2 8MB arrays" -> "What is the largest file g++ can handle"
I mean seriously
 
@Siliproksi you can dynamically allocate memory for the 8MB array and use the array as a pointer
but that won't be a good idea
 
3:33 PM
I'm assuming he meant an array declared in source like char data[] = {...};
 
hmmm, that could be one of the interpretations
but why am I the one who has to guess
sometimes I wonder why I even bother
 
it does take some effort to get back to the X problem when asked a Y question...
 
which is fine but not when you get
8 mins ago, by Siliproksi
Ah... This stackoverflow. Good Bye...
in response
 
focus on the "oh great! thanks!" responses and forget about the rest
 
4:14 PM
How much drying should you do?
 
until it's dry
 
Is it worth wrting

std::function<int(int, int)> op;
				if (dir % 3 > 0)
					op = std::plus<int>();
				else
					op = std::minus<int>();

				int* v = nullptr;
				if (dir % 2 == 0)
					v = &y;
				else
					v = &x;
				op(v, 1);

				if (!dir == 0)
					--max;
instead of
if (dir == 0)
{
--y;
--max;
}
else if (dir == 1)
++x;
else if (dir == 2)
++y;
else if (dir == 3)
--x;
Meh, didn't format correctly
 
it is possible that you're attempting to fix this at the wrong level
for example, instead of manipulating xs and ys directly
you can have a Point type
 
Yes, but little code is being repeated ;)
ok
But the original with the ifs and elses is still more readable
Oh, also there's a typo with the max... should be if (dir != 0) adding another if clause to the bottom code
 
std::complex<double> point(5, 4);
std::array<std::complex<double>, 4> directions = { {0,-1}, {1, 0}, {0, 1}, {-1, 0} };
point += directions.at(dir);
 
4:20 PM
Nice! I like that solution. Never heard of std::complex tbh, but I'll read about it
 
note that std::complex uses floating point numbers, not integral numbers
 
Yeah, I don't think it will be a problem
 
if you need integral numbers, you'd probably want to write your own Point type. depending on how big your program is, it may or may not be worth it
 
But is it okay to use std::complex as a Vector2 here?
 
if it's 100 lines or sth, then maybe not
@kim366 depending on who's asking. it's perfectly fine with me
 
4:23 PM
Okay, thanks for your time!
 
complex numbers have some operations which don't make much sense for 2 dimensional vectors (like division), so some people consider this abuse of semantics
 
I mean I don't know complex numbers at all, so it's fine by me :)
 
@kim366 Complex numbers save the day when you work with 3D stuff
I am porting the C++ complex lib for PAWN for that reason.
PAWN is used in counter strike, SAMP and many embedded systems.
 
yes, in 3D you also need 4x4 matrices, 3 dimensional vectors and quaternions
 
I use complex numbers to work in a 2D plane and use the z as depth.
it has so much math
it check's player's aim and does some analysis to guess if the player was using an aimbot
had to do it without complex numbers or vectors becaz there wasn't a library for complex numbers
 
4:59 PM
does anybody know how to use eclipse CDT?
 
no, no one knows how to use eclipse CDT
 
sarcasm?
 
probably
 
XD, very nice
anyway
 
I guess, it's unlikely that no one among 7 billion people on earth is familiar with eclipse CDT
 
5:01 PM
but I'm not asking to all these people
just to the ones currently chatting in this room
anyway
I have two projects
and I'd like to make one of them to use the source of the other one
is that possible?
Or am I forced to create a static library
or dynamic
some how I need to work on both of them together
any "clever way" to do that?
 
add a file to both projects maybe
dunno I don't use eclipse
 
XD
what do you use?
 
maybe someone else here does
 
It's a crappy IDe
but I'm forced to use it xD
 
eclipse seems to use regular makefiles internally
 
5:08 PM
How can I "run" through every syllable of the string and compare it to other string syllable ,so I can see which word is "bigger" comes first alphabetically than the other?
 
I´m doing the following with no sucess if(p != '\0'&& name1[p] > name2[z] && name2 != '\0' && z != '\0') in which p and z are the syllable in each run
@milleniumbug cannot use implemented functions
 
ah, so homework?
iterate over both strings, and compare each character with <
 
@milleniumbug Something like it ;). The problem is that i cannot get each syllable in the variable
 
"syllabe"?
I'm guessing you mean "character"
 
5:16 PM
How can I do the following, per example: Anchor and Bing. Anchor is located before the Bing alphabetically, so I have to run Anchor like p = A and z = B and then once they´re different the program should say anchor is "bigger" than bing.
 
@rockethon You have to implement the lexicographic order
 
yes I mean character @milleniumbug
 
you get the strings, you check both starting characters whether they're different
if they are, you can stop checking because you can give the answer
otherwise you move on to the next character
 
I already have that part I just need to know how can i get the character assigned to a variable
 
if you have a string s then you can access the character at the nth position with s[n] (s[0] is the starting one)
 
5:22 PM
Ok I´m going to try that way and let you know, "n" should be an int or char?
 
it's an index
 
ok, forget about eclipse I have another question
are these supposed to be extension of the C types?
so they have two complement representations etc bit for wider word size?
 
> The type uses a sign-magnitude representation internally, so type int128_t has 128-bits of precision plus an extra sign bit. In this respect the behaviour of these types differs from built-in 2's complement types. In might be tempting to use a 127-bit type instead, and indeed this does work, but behaviour is still slightly different from a 2's complement built-in type as the min and max values are identical (apart from the sign), where as they differ by one for a true 2's complement type.
> That said it should be noted that there's no requirement for built-in types to be 2's complement either - it's simply that this is the most common format by far.
@user8469759 from the page you've linked
 
6:05 PM
@milleniumbug well, now I understand why not in headers, but why not elsewhere?
 
for me, needing to add std:: when adding a declaration is enough reason not to use them in implementation files
If I don't use them in both places, I can simply copy paste the function, remove the body and add a semicolon
 
so you never use vectors/strings?
 
no, I always type std::vector<T> instead of vector<T>
 
oh, sure
but that's std::
I thought you didn't use std::...
1 min ago, by milleniumbug
for me, needing to add std:: when adding a declaration is enough reason not to use them in implementation files
or what did you mean?
 
let's say you have using namespace std; in your implementation file
 
6:08 PM
implementation files is the cpp to accompaniate the h?
 
your function definition is something like string my_function(vector<string> s) { /* stuff */ }
now when you need to change a thing there, you can't just copy paste the function, remove a body, and add a semicolon
string my_function(vector<string> s); // what is string, there's no using namespace std; in a header
so I use full qualification std::string my_function(std::vector<std::string> s) { /* stuff */ }
now the declaration is std::string my_function(std::vector<std::string> s);
for me, that's reason enough to not use using namespace std;
but there's also ADL issues, conflicts with other functions and so on
 
Any idea why this doesn´t work: printf("The %s its bigger than %s",&name2,&name1); ?
 
Nov 29 '16 at 17:38, by milleniumbug
PSA: Enable warnings in your compiler if you haven't already (in gcc: -Wall -Wextra -pedantic)
 
@rockethon are name2 and name1 arrays?
the array symbol is a pointer
char arr[] = "asdasdad";
arr is a pointer
You can add -Werror too if you want warnings to be triggered as errors.
 
they are char and the 1st %s seems to work
 
6:15 PM
o0
char is not a string
strings are supposed to be null terminated
char a = 'a', b = 'b', c = '\0';
cout<<&a; would work
you'd get ab
@rockethon can you show your code?
 
if(name2[z] > name1[p] && name2 != '\0' && name1 != '\0'){ {
printf("The %s its bigger than %s",&nome2,&nome1);
n = n+1;
p = p+1;
z = z+1; }
 
have you enabled warnings
 
Any tip @YashasSamaga?
 
@rockethon show the declaration and as milleniumbug said, enable warnings. Compiler should actually catch stupid mistakes.
what are you doing lol?
name2[z] indicates that it is an array
 
char name1[5];
char name2[5];
int n = 0;
int p = 0;
int z = 0;
 
6:28 PM
name2 != '\0 indicates that it is a char
remove the & before name1 and name2, and ur code will work
char name1[5]; can be written as char *name1 = {0,0,0,0,0};
both are identical
 
@YashasSamaga no, it can't
 
@milleniumbug char *name1 = "\0\0\0\0\0";
that would work?
@milleniumbug why doesn't that work?
 
@YashasSamaga it would compile, but won't be equivalent
 
how?
of course they are initialized differently
 
@YashasSamaga can you show me what you mean by "remove the & before name1 and name2, and ur code will work"
 
6:31 PM
printf("The %s its bigger than %s",name2,name1);
 
char name1[5]; is uninitialized variable, and char* name1 = "\0\0\0\0\0"; is actually invalid C++11, but valid C++03 using a deprecated conversion
 
"\0\0\0\0\0" I added an extra \0 I see
but that wasn't the issue you were talking about I guess
 
also the latter points to statically allocated string which modifying it counts as UB
 
AH!
why is char* name1 = "\0\0\0\0\0"; invalid though?
 
@rockethon coliru.stacked-crooked.com/a/b0dba43caddc349d <- your code with warnings enabled
@YashasSamaga because "\0\0\0\0\0" is of type const char[6]
 
6:36 PM
I have been using such code :/
 
you were relying on deprecated conversion of string literals to char*
it's illegal C++11, but some compilers may still allow it as an extension when you don't enable the -pedantic mode
modifying a literal is still UB though
 
I've never noticed any UB behaviour :/
 
that's what UB means
 
I ensure that I don't go past the initial size
 
Why is it telling me when I insert names like Marco and Maria that the names are the same and not that Maria is bigger than Marco?
 
6:41 PM
You have redundant code
z = 0, why did you use name2[z]?
I am guessing that you forgot to add a loop
 
Because Z is the variable that runs through the name
characters
 
you do the check only once
I have a strong feeling that you missed out a loop
the p = p + 1, n = n + 1 makes me feel so
anyway I got to go. bye. it's 1 AM here
 
@YashasSamaga so I only have to get 1 loop for both names
 
yes, you can use a single loop to check both names
 
7:10 PM
Guys , can you give me a link or maybe explain to me how to transfer the digits from a string "1230871209381723012" to a variable? Thank you in advance.
I've been trying to find something but I can't seem to find what I need
 
"to a variable" of what type
 
int
 
nwp
doesn't fit
 
well I only want the digits
so v[0] is 1; v[1] is 2; v[2] is 3; v[3] is 0 etc
 
then you don't want int
 
nwp
7:13 PM
@ChorMay the string already does that for you
 
std::string v = "1230871209381723012"; // v[0] is '1', and so on
 
can I make let's say v[0] + v[1] = 3?
 
int digit = v[0] - '0'; // digit == 1
 
ok awesome, thank you a lot
Also , I once went to a c++ contest and they had a "C++ Reference" on desktop with all the functions (offline mode). Is it possible to replicate that on my computer?
 
en.cppreference.com/w has an offline archive
 
7:17 PM
Ok, awesome! Thank you!
 
 
2 hours later…
9:02 PM
hello?
 
nwp
@user8469759 nohello.com
 
Hi guys
I'm designing an algorithm
to implement the triangulation of a polygon
where this polygon
is represented using a doubly connected edge list
I don't know if you're familiar with this stuff or not
but basically
I need to understand
what's the best way to "wrap an object" in order to add additional information
with reference to that algorithm
do you think you can help me to work out a solution?
to me these algorithms are quite difficult to implement
 
nwp
@user8469759 struct Wrapper{ Object old_object; Additional_information info; };, though I don't really understand the question
 
maybe this problem is equivalent
say you have a graph implemented using adjency lists
and say you want to implement the BFS search algorithm
for that specific algorithm you need to mark the nodes
how would you implement the marking?
it's not a field that the nodes have
you could create a list of marked nodes
 
nwp
9:19 PM
@user8469759 yeah, that's what I would do
 
but I don't think the list would be efficient
ok, but if you are about to explore a new node
 
nwp
does it need to be efficient?
 
well, yea
that's what I'm trying to learn
how to efficient implement certain kind of algorithms
if you when explore a new node you have to go through a list
I don't think that would be great
this is why I was thinking maybe an helper class could help
but I'm not sure how to design properly the wrapper
 
nwp
by efficient do you mean the complexity of the algorithm or the performance of it?
 
I would say both
but let's start with the complexity
in theory a BFS has linear complexity
using a list for searching whether a node is marked
would probably bring the complexity to O(N^2)
 
nwp
9:32 PM
I forgot how adjacency lists work, but essentially you have a vector<pair<Node, vector<Node>>> adjacency_list; right? Then you could use a vector<bool> marked; and to get the status of a Node you just get the index from the adjacency_list and use that to index into marked which would mean O(1) overhead per node which doesn't ruin algorithm's complexity.
 
If you use the vector class
wouldn't I be bounded to a fixed number of nodes?
how about if I need to add a new node
 
nwp
a std::vector can grow to hold as many items as required
what did you use?
 
your proposal of data structure to me, but maybe I'm wrong, recalls a matrix
so if the graph is sparse many of the nodes would be unused
or maybe I'm missing something
let me think
ok you basically have an array indices represents node labels
but you would use an integer as index of the adjacency list
which means if the arc (i,j) is not present you would have an empty entry
so yes it is equivalent to a matrix
and if the graph is sparse
 
nwp
@user8469759 it wouldn't be a matrix because the inner vectors can have different sizes
 
many entries would be unused
 
nwp
9:39 PM
and you would never store empty objects
 
how are vectors internally allocated?
 
nwp
(not counting internal memory management of vector)
@user8469759 an array that grows by a factor if out of capacity
 
and in the adjacency vector
what's the meaning of the index?
 
nwp
@user8469759 I think it doesn't have one. Wikipedia said the list is conceptually unordered.
 
why doesn't have one? isn't it a vector ?
 
nwp
9:43 PM
it is a vector, but you just don't use the fact that the elements are ordered
 
isn't the management more difficult then?
 
nwp
not really, I don't think you can translate giving up the ordering into a performance increase
you can make erasing elements more efficient if you don't care about the order, but you don't erase elements, so it doesn't matter
 
10:16 PM
Do you agree with me that if the nodes had a boolean field "marked" than I wouldn't have problem right?
I just find a bit weird there's no workaround for this thing
 
nwp
I thought the vector would be a solution, so I guess I didn't understand the problem.
 
It is a solution, I just don't think it's the best one
I was looking at this
and specifically this
for (; sources_begin != sources_end; ++sources_begin) {
      Vertex s = *sources_begin;
      put(color, s, Color::gray());           vis.discover_vertex(s, g);
      Q.push(s);
    }
    while (! Q.empty()) {
      Vertex u = Q.top(); Q.pop();            vis.examine_vertex(u, g);
      for (boost::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
        Vertex v = target(*ei, g);            vis.examine_edge(*ei, g);
        ColorValue v_color = get(color, v);
        if (v_color == Color::white()) {      vis.tree_edge(*ei, g);
which is the algorithm
they use the "put(color,u,Color::bla)"
as equivalent of marked
although it is parametrized
 
 
1 hour later…
11:36 PM
I think I've found the solution
I can create a class Vertex
such class Vertex can have a pointer to a VertexDescriptor (how don't know how to call it) which is a class having additional data
the descriptor can be abstract in case I need it so I can use different descriptors in different algorithm
So when I run the algorithm
I create an array of descriptors, and for each vertex I attach a descriptor to the vertex
and for the specific case of the BFS the descriptor can be a simple data stracture with 1 field
 
00:00 - 15:0015:00 - 00:00

« first day (227 days earlier)      last day (2632 days later) »