« first day (354 days earlier)      last day (2504 days later) » 

12:20 AM
seems like the "transformed" intervention is dereferencing the vector iterator but i still fail to understand how and why
 
 
7 hours later…
7:49 AM
if i do something like this std::string(argv[1]) += "iou", if argv[1] is = "ae", will that make it "aeiou" ?
argv is a char *
 
nwp
@jeyejow += wouldn't make sense. You might add "iou" to the temporary string, but then it disappears, so it is useless
you can do std::string(argv[1]) + "iou" which gives you a std::string that contains "aeiou"
 
@nwp ohh, so how do i do to add x to a char *? should i just make a string with the value of argv[1] and work with that string?
 
nwp
@jeyejow that should be a char *[] actually
 
yes
 
nwp
@jeyejow you cannot add to a char *, but you can use a std::string for that
 
7:54 AM
hmmm ok, thanks!
 
nwp
you could do something like std::string s = argv[1]; s += "iou";
 
@nwp ye, that is what i was thinking
the only problem is that i think the funtion i use needs a char * and not a string
yep, it needs a char *, what can i do? can i convert the string to a char *?
 
nwp
A good solution would be to change to function to take a std::string instead. If that is not an option use s.c_str() which gives you a const char * with the content of the string.
 
oh yes, i forgot about the c_str(), ill do that ^^
@nwp i have a problem, i need to add "\\.\" in a string, for example, if the string is "F:", i need to add "\\.\" to the begining of it, so it will stay like this "\\.\F:". the problem is that when i try to add, i do it like this bf.insert(0, "\\.\" ); but that gives me an error unless i do this bf.insert(0, "\\.\\" );, do i need to do this : bf.insert(0, "\\\\.\\" ); so it works? cause i think "\\" reads as one \
ill try
if you have a better solution please tell me
 
8:10 AM
you need to escape a \ with an extra \. So "\\.\" should be input as "\\\\.\\"
 
nwp
Yeah, '\' is a special character to make for example '\n' a newline. You need `\` to make a regular \.
 
i see, thanks :o
 
nwp
You can also use raw string literals to avoid escaping stuff: R"(\\.\)"
@nwp stupid markdown. You need '\\' to make a '\'.
 
ic
i have a problem
i have this function that takes arguments like this
int filetodevice(char* dev, char* wfile, int get, int start, int position)
{
and i call it like this
filetodevice(bf.c_str(), output, get, start, fileposition);
bf is a string
it gives me a error saying argument of cont char * is not compatible with char *
in the bf
why is it saying that? im asking for a char *, not a const char *
are arguments always const?
 
bf.c_str() gives you a const char*
 
8:20 AM
ohhh
 
in other words you are passing it a const char* which cannot be implicitly converted to char*
 
so i need to change the function to take a const char * and not a char * ?
 
or is there other way around it
ok
 
Hi guys
reading through what volatile and mutable means
I have this
The volatile keyword informs the compiler that a variable will be used by multiple threads. Variables that are declared as volatile will not be cached by the compiler to ensure the most up-to-date value is held.

The mutable keyword can be used for class member variables. Mutable variables are allowed to change from within const member functions of the class
For the volatile
what does it mean the "cached" word in that context?
while for the mutable
not sure what that means
 
8:50 AM
does annyone know were to find cool ascci art to put in my console program? like some programs n linux have?
i think it would look really cool if i have some sort of ascii art in mine
the ascii art i found is usually too big and it doesnt fit
 
mutable is a way to get around const restrictions without having to const casts
 
nwp
@user8469759 That are really shitty and outdated description. Don't believe a word it says.
 
for example an object that represents the data of a file but reads it lazily
you make the pointer to the read data mutable and you can then populate it on first read
 
@user8469759 it means that changing that variable isn't protected by const-ness of an object
@user8469759 exactly what it means in every other context. It effectively invalidates the cache at every read.
 
9:11 AM
@BartekBanachewicz but both specifically refer to the context of embedded system
is that right?
 
9:22 AM
@user8469759 not really, no
 
I'll write down some code look at the assembly and see what happens
probably the best way to understand it
because if you don't elaborate I really don't understand what you mean
would the volatile keyword affects global variable as well?
 
@user8469759 I wouldn't agree
@user8469759 it would
@user8469759 I don't really understand what you don't understand ;)
volatile means "always read this directly from memory and don't use the regular cache for it". mutable means "it's fine to change this value even if the object is const"
this is the simple part. The hard part is finding uses for them.
 
@BartekBanachewicz that's probably my problem, I can't see the benefit
let me focus on the volatile
I'll share some code in a bit
 
it's not that useful nowadays when we have atomics and stuff admittedly
I don't remember myself using volatile in a program ever, actually.
 
I'm not neither sure what should I write down as code to see a sensible difference
I saw an example video from atmel
where basically it was showing that if you have a multithreaded application
and you do perform optimization
you can get something screwed
but declaring the variable volatile
would make things work
 
9:34 AM
@user8469759 the easiest example would be volatile bool flag = false; while (!flag) { }
 
so should I write down a multithreaded application that modify a global variable, once volatile and once not volatile and check the difference?
 
@user8469759 see above. Is it an infinite loop? What if it there's no volatile?
 
@BartekBanachewicz single threaded or multithreaded?
 
the difference is either going to minimal or massive
 
@user8469759 single-threaded is a special case of multi-threaded ;)
 
9:35 AM
single thread don't have the same problem as a multi thread
this is why I'm mentioning it
anyway
I don't know what would happen if there's no volatile
 
@user8469759 the compiler could replace the code with while (true) { }
 
one of the caches the compiler has available is the registers
 
if you optimize it
 
@user8469759 which you have to assume happens
 
9:37 AM
so while(flag){} can be optimized to auto tmp = flag; while(tmp){}
 
TLDR you can not know what volatile is and move on with your life
 
#include <stdio.h>

int main(int argc, char** argv) {
   volatile bool flag = false;
   while(!flag) {
   }
   return 0;
}
this is the code
I've compiled with
g++ main.cc -S
and read the file
main.s
sorry
 
@Idle001 Look up Boost.Range documentation for boost::adapters::transformed. Basically you have iterators which wrap other iterators.
 
	.file	"main.cc"
	.text
	.align 2
.globl main
	.type	main, @function
main:
.LFB2:
	pushq	%rbp
.LCFI0:
	movq	%rsp, %rbp
.LCFI1:
	movl	%edi, -20(%rbp)
	movq	%rsi, -32(%rbp)
	movb	$0, -1(%rbp)
.L2:
	movzbl	-1(%rbp), %eax
	xorl	$1, %eax
	testb	%al, %al
	jne	.L2
	movl	$0, %eax
	leave
	ret
.LFE2:
	.size	main, .-main
.globl __gxx_personality_v0
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.long	.LECIE1-.LSCIE1
.LSCIE1:
	.long	0x0
	.byte	0x1
	.string	"zPR"
	.uleb128 0x1
	.sleb128 -8
	.byte	0x10
	.uleb128 0x6
there's no optimization
with optimizaiton
I get this
	.file	"main.cc"
	.text
	.align 2
	.p2align 4,,15
.globl main
	.type	main, @function
main:
.LFB14:
	movb	$0, -1(%rsp)
	.p2align 4,,7
.L2:
	movzbl	-1(%rsp), %eax
	testb	%al, %al
	je	.L2
	xorl	%eax, %eax
	ret
.LFE14:
	.size	main, .-main
.globl __gxx_personality_v0
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.long	.LECIE1-.LSCIE1
.LSCIE1:
	.long	0x0
	.byte	0x1
	.string	"zPR"
	.uleb128 0x1
	.sleb128 -8
	.byte	0x10
	.uleb128 0x6
	.byte	0x3
	.long	__gxx_personality_v0
	.byte	0x3
	.byte	0xc
	.uleb128 0x7
(-O3 flag)
 
lol gcc 4.1.2
 
9:44 AM
	.file	"main.cc"
	.text
	.align 2
	.p2align 4,,15
.globl main
	.type	main, @function
main:
.LFB14:
	.p2align 4,,7
.L2:
	jmp	.L2
.LFE14:
	.size	main, .-main
.globl __gxx_personality_v0
	.section	.eh_frame,"a",@progbits
.Lframe1:
	.long	.LECIE1-.LSCIE1
.LSCIE1:
	.long	0x0
	.byte	0x1
	.string	"zPR"
	.uleb128 0x1
	.sleb128 -8
	.byte	0x10
	.uleb128 0x6
	.byte	0x3
	.long	__gxx_personality_v0
	.byte	0x3
	.byte	0xc
	.uleb128 0x7
	.uleb128 0x8
	.byte	0x90
	.uleb128 0x1
	.align 8
.LECIE1:
.LSFDE1:
	.long	.LEFDE1-.LASFDE1
that's the same (optimized code but without the volatile)
what's the main difference among these three I should spot
except the first one is long
 
@user8469759 you're going at this all wrong
it's not about one output from one compiler
that's not how you understand the language specification; you don't use or need a compiler for that
C++ is defined without resorting to generated assembly
 
so there's no relation between the output of the compiler and the volatile keyword
is that what you're saying? Or am I still getting it wrong
?
 
the last snippet is different
 
@milleniumbug I can see that, but which part is eventually relevant for the discussion?
 
the one which is different
hint: it's around L2 label
the rest is basically asm boilerplate for exception handling
 
9:55 AM
.L2: jmp .L2 is an infinite loop
 
and basically the volatile tells to the compiler to not perform any optimization
on that variable
or object I suppose
is that the thing at the end of the day?
Can I relate somehow those assembly to what @BartekBanachewicz was saying about the caching stuff?
 
10:10 AM
@user8469759 didn't we just do that? the "cache" is an infinite loop
 
nwp
@user8469759 If you have some time I recommend watching this 30 minute talk. It has some faults but it will greatly increase your understanding.
 
@nwp I'm watching the video
 
 
2 hours later…
12:42 PM
should i use mutable over const if i have a function that takes a const char *?
 
nwp
@jeyejow you can't, it is not valid C++
 
wat
but i saw that video
 
@jeyejow mutable is for member variables that need to be modified by const functions... which I would discourage for a lot of reasons
 
hmmm ok :o
 
Herb makes a good point that const member functions imply they are thread safe, modifying things from const member functions could a) break that b) breaks the implied contract that most developers assume which is that const won't allow for mutation
mutable is an escape valve that exists for quite a few reasons, but like the str* functions should be avoided
 
12:46 PM
ic
 
The only example I can think of where mutable is useful is some kind of lazy evaluation and still having a const getter
 
should i use vectors over arrays as arguments?
i need to learn how to use vectors, they seem really usefull
 
nwp
depends of the requirements of the function
 
@jeyejow Prefer spans
 
@jeyejow vector is useful when you need a resizable array where elements are contigious in memory
 
12:51 PM
@Mgetz never eard of that :O
 
@jeyejow they are working on a version of it for the standard
 
@PaulD i see
 
this is a pre-standard implementation
 
@Mgetz are they like vectors?
 
@jeyejow no they are like a pointer and a length, but in a convenient package that can be passed around without knowing the underlying container
so you don't have to use a template two create a version for array and vector
 
12:54 PM
@Mgetz that seems interesting, expecially since im trying to learn pointers, maybe i could learn something by using spans, do you have anny link that teaches how to use them? or is it easy to find with a google search?
 
@jeyejow you'd pass them just like you'd pass any other object gsl::span<foo> foo_span
if you need to know that there are at least N then you'd do gsl::span<foo, 15> foo_span
only replace the 15 with whatever N is
 
@Mgetz im pretty new to programming so im kinda slow, so gsl is a namespace? and span is a class of gsl, it takes a foo type?
am i analysing that correctly?
 
@jeyejow roughly, that's close enough
 
ok, ill try the span in a project
what is a lambda?
 
it's a anonymous function recognizable by the [] before the param list.
auto foo = [](int a, int b){return a<b;};
 
1:08 PM
i dont understand, i read this msdn.microsoft.com/en-us/library/dd293608.aspx
@ratchetfreak in your example foo would be = to what?
a and b?
a<b?
 
nwp
Anonymous function is not a good description. It is not anonymous as it has the name foo and it is not a function but a struct/class.
 
why should i use lambda?
 
no foo is a object you can call operator()(int, int) on aka do foo(1, 2) and it will return whether a is less than b
 
@nwp depends, and depends... I wouldn't confuse someone with those details right now
 
with non-capturing lambdas it's to avoid needing to define a one-use function elsewhere
 
1:13 PM
so we use lambdas to avoid using functions we only need to use once? why do we even use lambdas then? we could just write the code
 
it keeps callback code together with the registering code
and you don't have to name the callback!
you can also make it capture local variables
either by ref or by value
 
ohh i kinda get it
 
in C when using callbacks you usually see a extra void* usercontext param, capturing embeds that along with lifetime management of the captured data
 
nwp
@jeyejow A typical example is sorting a list of cars by weight, which you need to tell the sorting function, otherwise it has no clue how to sort cars.
 
Anyone here knows glm?
 
nwp
1:18 PM
@MuhamedCicak just ask the question
 
@nwp Sure :)
I want to work with matrices in 2D. I wrote output in the code examples. So, this code works as expected: pastebin.com/hcme18uy but its for 3D. I want 2D, so, I tried this. But this one doesnt work as expected: pastebin.com/ZfeEyrC7
 
suppose you have an representing contiguous intervals as orderd set of number
like
A = {1,4,5,9,11} represents the intervals [1,4), [4,5),[5,9),[9,11]
and you have a value x in [1,11]
would be the fastest way to find the interval to which x belong the classic binary search?
O(ln n) time?
 
@user8469759 Assuming the sizes of the intervals are somewhat predictable, you can use an interpolating search, and get something like O(log log n).
 
@user8469759 bin search on the lower bounds
you can use an estimator to bias each step towards the lower or higher end of the scale
works great when each interval is the same size but falls flat when they grow exponentially
 
1:35 PM
@nwp Any solution to my question?
 
@ratchetfreak You're re-inventing an interpolating search on the fly. It can work fine with an exponential distribution--you just need to take that into account in your interpolation. It will run into a problem if you have a distribution that's completely unpredictable (but experience indicates that such things are quite unusual).
 
can someone explain me this for cycle im having trouble understanding it, this is the for cycle code:
 for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';
this is the full code
#include <iostream>
#include <vector>

int main ()
{
  // constructors used in the same order as described above:
  std::vector<int> first;                                // empty vector of ints
  std::vector<int> second (4,100);                       // four ints with value 100
  std::vector<int> third (second.begin(),second.end());  // iterating through second
  std::vector<int> fourth (third);                       // a copy of third

  // the iterator constructor can also be used to construct from arrays:
i saw it while learning to use vectors here cplusplus.com/reference/vector/vector/vector
 
nwp
@MuhamedCicak Not my field. Casually looking over it makes me think the last argument to notTrans should be 0, but I'm not sure.
 
@JerryCoffin and you can defend against it by bounding the pivots it picks to some relative bounds (like never getting within 10% of the edge)
 
@ratchetfreak Might be useful, but I'm not sure--I've never tried it.
 
1:41 PM
std::vector<int>::iterator it
whats is this creating
is that the same and int it; ?
 
@JerryCoffin bounding the pivot selection like that will maintain the log n complexity even for adversarial input .
std::vector<int>::iterator is a type.
it is a default constructed instance of that type
 
@ratchetfreak i dont understand, it has <int> so isnt it a int?
 
@ratchetfreak Does seem like an interesting modification to the basic approach.
 
@nwp I guess I will just use 3D, but setting z to 0 and last matrix column to 1
 
template<typename A>
class foo{
    typedef std::string type;

}
 
1:51 PM
@jeyejow <int> by itself isn't anything. std:vector is a template. std::vector<int> is an instantiation of that template. std::vector<int>::iterator is a name defined inside of that instantiated template. Its type has essentially nothing to do with int itself.
 
foo<int>::type is std::string, completely unrelated to the template param
 
@JerryCoffin so when i say « std::vector<int>::iterator it; im creating a object of type iterator that holds an int?
 
@jeyejow You're creating an object of type std::vector<int>::iterator, which is used to iterate an object of type vector<int>. The iterator itself could be a pointer, or it could (more likely in a modern implementation) be some class that defines a few operations (++, *, ==, !=, etc.)
When you dereference the iterator (i.e., use *it) that will yield an int (assuming the iterator is valid at the time).
 
so std::vector<int> x; creats an array of ints, and std::vector<int>::iterator iterates an object of type vector<int>? what does "iterates" mean? @JerryCoffin
 
std::vector<int>::iterator obeys a specific contract
that specifies which operations are available and what the results will be,
the canonical use of an iterator is for(std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it){ int current = *it; ... }
that will loop over all the ints inside vec
 
2:10 PM
ohhhh so it represents a position in a vector
i get it
 
 
1 hour later…
3:20 PM
hello
I have a MFC doubt
Is here the place to ask?
 
you can ask, but I don't know MFC
maybe someone else will drop later who knows
 
 
7 hours later…
10:01 PM
hi,
I've a map<string, string> and I'm using 'if' condition to check first element to set the second element. Such logic makes the code very ugly. Please help me with some ideas.
 
1 message moved from Lounge<C++>
 

« first day (354 days earlier)      last day (2504 days later) »