[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 325
Thread images: 23

File: 1496943734332.jpg (195KB, 798x770px) Image search: [Google]
1496943734332.jpg
195KB, 798x770px
Previous thread: >>60841126

What are you working on, /g/?
>>
Your mom
>>
>>60843127
C++ can't do this
    foreach(index, number; numbers) 
if (index == number)
//do stuff
}
>>
>frog thread
What subreddit are you going to now that 4chan is clearly fucking over and just another part of reddit now, /g/??
>>
haskell!
>>
>>60843145

anon can't maintain a counter
>>
>>60843145
>mismatched curly brace
What did he mean by this?
>>
dumb frogposter
>>
>>60843166
C++ cannot enumerate foreach!
>>
Reposting
Challenge:
Get the index of the current element of a range based for loop in C++ without causing undefined behavior.
>>
>>60843166
Really, are you going to defend this with that argument?
>>
>>60843183
Impossible
>>
>>60843145
FOR WHAT PURPOSE

you can't do it in java either, because if you're using a foreach you either don't need the index or you're FUCKING RETARDED

KILL YOURSELF
>>
>>60843198
C# can do it, even (((Rust))) can. That's a new fucking low for C++
>>
>>60843213
C# and rust are shit tho

java and C++ are both industry-leading programming languages
>>
>>60843145
This hurts a sepples cuck
    foreach(index, number; numbers) 
if (number == some_value)
return index;
>>
>>60843232
Really? Are you seriously defending this?
Did anyone brainwash you?
>>
>>60843237
>>60843243
rustfags can't answer this simple question:

FOR WHAT PURPOSE
>>
>>60843246
I'm not a rustfag. but >>60843237 should explain you why. If that is you have a single brain cell left
>>
>>60843257
LITERALLY KILL YOURSELF YOU LITERAL FAG FUCK OFF

YOU'RE NOT WASTING ANY MORE OF MY TIME THIS IS YOUR LAST (YOU) FROM ME

LITERALLY KILL YOURSELF TRANNY FAGGOT
>>
>>60843232
>hurr durr other languages are shit so mine is better
The EXACT same strategy rust shills take to shill their lang, not anymore!
>>
>>60843237
for(size_t i = 0; i < array.size(); i++) {
if(array[i] == some_value) return i;
}

This is far more readable, and perfectly possible to do in C++.
>>
>>60843272
>autistic meldown
C++
Can't
Enumerate
For loops!
>>
>C++
>Can't
>Enumerate
>For loops!
/care
>>
>>60843280
>This is far more readable
No it isn't, it looks like utter garbage eww
I might as well use a fucking while (true) loop
>>
>>60843272
Are you crying right now?!
>>
>>60843280

>This is far more readable
lol
>>
File: 1495641113909.png (72KB, 1016x98px) Image search: [Google]
1495641113909.png
72KB, 1016x98px
>>60843280
>That shit is readable
C++ajeets, everyone
>>
>>60843280
>far more readable.
Even if this were the case its more error prone.
>>
>>60843280
>>60843272
>>60843198
This is an honest question, guys. Are you brainwashed?
>>
>>60843127
#[derive(Debug)]
enum Intelligence {
Dumb,
Smart
}

#[derive(Debug)]
struct Frogposter;

trait IQ {
fn iq(&self) -> Intelligence;
}

impl IQ for Frogposter {
fn iq(&self) -> Intelligence {
Intelligence::Dumb
}
}

fn main() {
println!("{:?} {:?}", Frogposter.iq(), Frogposter);
}


Compiler Output:
rustc 1.18.0 (03fc9d622 2017-06-06)
warning: variant is never used: `Smart`
--> <anon>:4:5
|
4 | Smart
| ^^^^^
|
= note: #[warn(dead_code)] on by default


Output:
Dumb Frogposter
>>
>>60843272
>putting this much emotional load on C++
It ain't healthy man. Really just don't do that.
>>
>>60843293
>>60843306
The original was so unreadable it took me like 2 minutes to figure out what it's trying to do. Foreach with three arguments doesn't even make sense.
>>
well done /dpt/ you shitposted for 30 minutes and trigger an autistic while I learned how to write Java code that never runs the gc
>>
>>60843326
Why do you declare a constructor you don't use?
>>
>>60843331
If an exploded tuple confuses you that much I think you should work on that.
>>
    //this is unreadable(!)
foreach(index, number; numbers)
if (number == some_value)
return index;

//this isn't (!)
for(size_t i = 0; i < array.size(); i++) {
if(array[i] == some_value) return i;
}

//PSA: C++ damages your brain
>>
>>60843342
Other posters might be smart
>>
>>60843183
Assumptions:
- The container is laid out serially. If a container isn't laid out serially, its "indices" aren't called indices, they're called keys.
- The range-based for loop traverses the container's elements in index order. If not, it's a shitty container, and whoever tried to stick it in the algorithm I'm about to show you has done a bad thing and should feel bad.
std::vector<std::pair<typename container::value_type, typename container::size_type> > indices;
typename container::size_type i = 0;
for (auto elem : container) indices.push_back(make_pair(elem, i++));
>>
>>60843280
this
>>
>>60843359
JESUS FUCKING CHRIST WHAT ABOMINATION IS THAT
>>
>>60843355
The two are readable.
>>
File: 1494451359140.jpg (22KB, 500x396px) Image search: [Google]
1494451359140.jpg
22KB, 500x396px
>rust doesn't have a C-style for loop
>>
>>60843359
Note to explain thing: Using vector of pairs instead of map because the container might contain the same element more than once.
>>
>>60843322
They are not brainwashed, they are just trying to control damage. In fact any normal person can read and understand what this is doing just by assuming the variable names.
>>
>>60843378
dumb frogposter
>>
has anyone written a image classified for anime yet?
>>
>>60843378
Haskell doesn't even have a loop. That being said, Rust macros are powerful enough to completely emulate C99 style loops.

Let's see your shit lang doing that oh wait it can't
>>
>>60843359
I agree on the first assumption but not the second. There can be good reasons based on the iterator used.
I'll accept this as ok though.
>>
>>60843367
The challenge said "without causing undefined behavior."
It didn't say "without causing unspeakable behavior."
>>
>>60843359
EWW WTF is that ugly garbage?
>>
>>60843378
>>60843405
http://huonw.github.io/cfor/cfor/
>>
>>60843355
>needs all that fucking punction
C++ faggots are in clear denial
>>
>>60843414
see: >>60843407
It's ugly sepples-speak for "just declare an int and increment it as you go along and that's the index, and if it's not, then you're container a shit"
>>
>>60843422
Frogposter utterly btfo. This is something new (!)
>>
>>60843414
It's called "C++", anon!
>>
>>60843345
``Tuples" are only used by those who are afraid of pointers.
>>
File: 1472109979150.jpg (19KB, 499x499px) Image search: [Google]
1472109979150.jpg
19KB, 499x499px
>rust doesn't have a C-style for loop
>>
File: 1495093750862.jpg (35KB, 640x640px) Image search: [Google]
1495093750862.jpg
35KB, 640x640px
>>60843462
Stupid fucking frogposter >:(
>>
>>60843460

tuples are just a convenient alternative to adhoc structs.
>>
>>60843460
C is for those who are afraid of assembly.
>>
File: git gud.png (4KB, 128x143px) Image search: [Google]
git gud.png
4KB, 128x143px
I have a local git repo connected to a remote one. Some time ago I made branch A on top of the master, made a commit, and then created branch B on top the A branch, and made a commit to B, and everything was pushed to the remote. Eventually, the A branch has been merged into master on the remote, and I pulled everything back into local repo.

Now I need to rebase the B branch no top of the master. Apparently, I can do `git rebase master` and get it rebased in my local repo, which creates a new commit on top of the master, which is apparently what I want. But when I try to push it to the remote I get
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

which is not that I want. So, how do I rebase it on the remote?
>>
>>60843462
dumb frogposter
>>
>>60843183
>>60843359
>>60843367
>>60843407
>>60843414
>>60843450
>>60843441
In C, this is just:
int const len = sizeof(container)/sizeof(*container);
int i; for (i = 0; i < len; i++) printf("%d\n", i);
>>
File: moonman.png (747KB, 839x464px) Image search: [Google]
moonman.png
747KB, 839x464px
https://doc.rust-lang.org/1.2.0/book/dining-philosophers.html
>
fn main() {
let p1 = Philosopher::new("Judith Butler");
let p2 = Philosopher::new("Gilles Deleuze");
let p3 = Philosopher::new("Karl Marx");
let p4 = Philosopher::new("Emma Goldman");
let p5 = Philosopher::new("Michel Foucault");
}
>>
>>60843378
dumb frogposter
>>
>>60843460
Come on anon. 2 minutes. Face the fact, you have a problem.
>>
>>60843511
>1.2.0
>Posting outdated documentation
>>
>>60843495
>>60843513
Why /g/ hates this green cancer so much?
>>
>>60843511
>inverted swastika
kys
>>
File: 1473787744816.jpg (122KB, 750x651px) Image search: [Google]
1473787744816.jpg
122KB, 750x651px
>rust doesn't have a C-style for loop
>>
>>60843549
>Why do you hate cancer?
That's a tough question
>>60843558
dumb frogposter
>>
>>60843561
>frog posting
So this is where C++ajeets resorted to
>>
>>60843494
if I understand correctly, you have a branch B that's behind master and you want to replace master with B?

That's not reccomended because it'll destroy part of the history of master. The best practice action is to:
>checkout master
>create a commit that reverts the commits you dont want in master anymore, commit them
>switch back to B
>git pull and merge master into B
>merge B into master

if you dont care about maintaining the history of master (you can only do this if you own the remote repository and DONT do this if you work with other people)
>check out master locally
>checkout the last commit you care about
>merge in B, commit to master
>git push origin master --force
>>
>>60843561
Disliking some memes is fine. Being buttmad about them causes even more cancer.
>>
>>60843145
>>60843237

You're looking for something equivalent to Ruby's :each_with_index method? Why? The C++ way of doing this is with a C-style for loop.

for (size_t index = 0; index < numbers.size(); i++) {
auto number = numbers[index];
/* Do something here with index and numbers */
}
>>
>>60843598
You've got to go back
>>>/r/ibbit/knowyourmeme
>>
>>60843603

>The C++ way of doing this is with a C-style for loop.
That's cancer if you're doing anything with a non-constant index complexity, like a linked list. Just use your standard foreach and maintain a counter.
>>
>>60843617
>Fighting meme users by feeding them
Do you understand that it doesn't work?
>>
>>60843649
you feed them so that it hurts them all the more when you whip out the cane
>>
>>60843569
>actually defending frogposting
>>
>>60843588
Thanks, I've ended up doing push -f, since I didn't care about the history and other people at all.
>>
>>60843659
>actually greentexting
whomst arst thee quoth
>>
File: brainlet.jpg (47KB, 645x968px) Image search: [Google]
brainlet.jpg
47KB, 645x968px
>tfw too unintelligent to be a lisp weenie
>>
>>60843625

Indeed it is bad if you want to use a linked list, but to be fair, you should not be using a linked list in the vast majority of cases. Realistically, how many times do you need to both insert at middle a fuck ton of times AND have the index kept track of? Otherwise, yes, a counter with range style for is fine.
>>
>>60843183
If it's an std::vector or array you can get the index by subtracting the address of the element from the address of element 0.
>>
File: 1431346213392.png (9KB, 401x367px) Image search: [Google]
1431346213392.png
9KB, 401x367px
>rust doesn't have a C-style for loop
>>
>>60843703
That's right, Haskell provides both Lisp flexibility and static typing guarantees.
>>
>>60843721
You can implement any kind of type system you want with reader macros, or even another language if you want..
>>
>>60843721
>static
I think the word you're looking for is "strong"
For contrast, C is an example of a STATICALLY typed language
>>
>>60843145
size_t index = 0;
std::for_each(std::begin(numbers), std::end(numbers), [&index](const Number& nn) { if (index++ == nn) /* do stuff */ });


btfo.
>>
>>60843740
>You can implement
But why would you waste your time on it instead of taking an existing high-quality implementation?

>>60843758
Actually I meant "strong static", but I didn't bother to mention "strong" because "weak" typing does not provide any real guarantees.
>>
>>60843715
dumb frogposter
>>
>>60843791
>existing high-quality implementation?
No such thing.
>>
>>60843841
haskell!
>>
File: 1470058656351.jpg (136KB, 664x441px) Image search: [Google]
1470058656351.jpg
136KB, 664x441px
>>60843553
wrong
>>
>>60843714
Undefined behavior.
See >>60842459
>>60842532
>>
>>60843862
Nope
>>
>>60843866
>Undefined behavior.
None of those points would apply.
You would never be two past the end of the array.
>>
>>60843868
rude!
>>
>>60843866
std::vector and std::array are guaranteed to be contiguous so that they can match C array layout.

https://herbsutter.com/2008/04/07/cringe-not-vectors-are-guaranteed-to-be-contiguous/
>>
File: IMG_20170525_120444.jpg (4MB, 4032x3024px) Image search: [Google]
IMG_20170525_120444.jpg
4MB, 4032x3024px
>>60843553
It's correct. You're mistaking the Buddhist swastika.
>>
>>60843889
>Pointer-pointer isn't before the array
Only if your array starts at 0x0.
You can't have pointer arithmetic end up like that.

Which is stupid. It's because of early x86 as the post mentions.
It's undefined but probably fine in the large majority of cases
>>
>>60843918
>Only if your array starts at 0x0.
No.
>You can't have pointer arithmetic end up like that.
Yes, you can.

"When two pointers are subtracted, both shall point to elements of the same array object,or one past the last element of the array object; the result is the difference of the subscripts of the two array elements."

" In other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of
an array object, the expression (P)-(Q) has the value i−j provided the value fits in an object of type ptrdiff_t."

It's implementation defined whether ptrdiff_t can cover the same range as size_t, but as long as it can, it's well defined.
>>
>>60843863
>wrong
And how so? Is there supposed to be something in that picture that proves it?
Because all I see is several cow pies with legs.
>>
>>60844005
What ptrdiff_t isn't a size_t? It should be. It's incoherent.
>>
so are anti-rusters nazis or something?
>>
>>60844044
No, just dumb frogposters
>>
>>60844043
ptrdiff_t is signed.
>>
>>60844044
Nice try, Antifa.
>>
>>60844044
No.
What you may have heard is that rusters are anti-nazi. This is accurate, and there's nothing wrong with that; nazism is truly a despicable ideology.
Anti-rusters, on the other hand, are just good programmers.
>>
>>60844082

nazism > communism
>>
>>60844082
What's wrong with Rust? Except that linear types can be implemented in Haskell, resulting in a better language.
>>
>>60844092
You do realize everyone on 4chan would be sent to concentration/work camps under both, right?
>>
>>60844082
Nazi programmers did nothing wrong.
>>
>>60844092
My ideology, anti-killing-people-ever-ism, is superior to nazism. I have no interest in the question of whether nazism superior to communism, nor in the question of whether nazism is superior to communism.
>>
>>60844044
so are rusters communists or something?
>>
>>60844131
>I have no interest in the question of whether nazism superior to communism, nor in the question of whether nazism is superior to communism.
Excuse me, what I meant was:
I have no interest in the question of whether anti-killing-people-ever-ism is superior to communism, nor in the question of whether nazism is superior to communism.
>>
>>60844058
Oh.
>>
>>60843326
>rust
no
>>
>>60843326
did you just assume intelligence is binary, shitlord?
>>
>>60844114
>What's wrong with Rust?
You have to contend with the constraints of type safety every step of the way.
C is much better, in that if you write a function, all you have to guarantee is the type safety of what comes out of the function given the type safety of what goes into it. At any point in between you can do whatever crazy shit you need to do.
>>
>>60844225
>You have to contend with the constraints of type safety every step of the way.
Lol. "Constraints of type safety" are actually "constraints of correct code". Forced type safety stops being a problem as soon as you learn how to write a well-typed program.

>At any point in between you can do whatever crazy shit you need to do.
But in general case you can't guarantee the type correctness of the output if you do come random shit inside. And if you really-really need to do some random shit, you can mark the module as 'unsafe'.
>>
File: 1483829514331.jpg (74KB, 763x757px) Image search: [Google]
1483829514331.jpg
74KB, 763x757px
void main() {
auto p1 = new Philosopher("Ernst Krieck");
auto p2 = new Philosopher("Martin Heidegger");
auto p3 = new Philosopher("Alfred Baeumler");
auto p4 = new Philosopher("Herman Schmalenbach");
auto p5 = new Philosopher("Carl Schmitt");
}
>>
>>60843246
It's not Rust you fucking retard.
>>
>>60844300
>"Constraints of type safety" are actually "constraints of excessively careful code". Forced type safety stops being a problem as soon as you learn how to write a very slow program.
ftfy
>But in general case you can't guarantee the type correctness of the output if you do come random shit inside.
Well, yeah, but you shouldn't be doing RANDOM shit unless either you're implementing some kind of test case generator, or you're implementing an algorithm where order doesn't matter and you want to be catty about it.
>And if you really-really need to do some random shit, you can mark the module as 'unsafe'.
When did we even start talking about random shit? I'm talking more along the lines of pointers that are invalid unless dereferenced in a certain nonstandard way, casting things to incompatible types and operating on the result, etc.
Besides, you shouldn't need to mark something unsafe if it does things that would be unsafe in the general case but does them safely.
>>
>>60844379
rustfags are the ones who are salty about not having a C-style for loop and trying to bait C++ programmers for not having rust's perverted version of foreach
>>
>>60844141
so are 4channers nazis or something?
>>60843511
>>60843863
>>60844092
>>60844119
>>60844345
>>
>>60844345
(define philosophers (list 'john 'jack 'sam 'michael 'ed))
>>
>>60843357
That seems unlikely
>>
>>60844404
>rustfags are the ones who are salty about not having a C-style for loop
No I'm not.
Enumerations can be done just fine in Rust.

Any other use of C style for loops are more appropriately done with while loops.

So no, I'm not missing out on anything, so why would I be salty about it?
>>
File: Screenshot_2017-06-10_13-19-20.png (9KB, 265x179px) Image search: [Google]
Screenshot_2017-06-10_13-19-20.png
9KB, 265x179px
>>60844407
fuck off kid, don't mess with anonymous
imma hack u
>>
>>60844382
>Forced type safety stops being a problem as soon as you learn how to write a very slow program.

Wow, you literally have no fucking idea how type safety works, do you?
>>
File: antifa.jpg (384KB, 1400x933px) Image search: [Google]
antifa.jpg
384KB, 1400x933px
This is the face of Rust.
>>
>>60844453
>aliases hack to ping
>invokes it on localhost
o shit meng dat sum haxin skil don mes wid dis guy
>>
>>60844453
just showed everyone your IP mate. you're fucked
>>
What exactly is the purpose of std::for_each over a range based or even a normal for loop?
>>
>>60843145
>>60843178
>>60843183
>>60843283
>>60844448
yeah you're not salty at all

>>60843603
a tripfag being based for once, simply by stating the obvious, because this thread is such a troll-infesting circlejerk shithole
>>
>>60844470
Hey, that looks like me, except not morbidly obese and not living in filth with a senile old coot who shits herself.
>>
>>60844508
>>a tripfag being based for once, simply by stating the obvious, because this thread is such a troll-infesting circlejerk shithole
>calls someone else salty
>>
>>60843625
>linked list
rustfags everyone
>>
>>60844526
i'm not salty, i'm just stating the obvious, that there is no problem with loops in C++
>>
>>60844495
>std::for_each over a range based or even a normal for loop
I'd assume you'd use it to implement an O(n^2) algorithm.
As for why exactly you'd want to use two different loop syntaxes to do it, beats me.
>>
>>60844530
Don't knock linked lists, they're conceptually of critical importance because more advanced linked data structures such as dags are very useful and don't have intuitive array-based counterparts.
>>
Do NOT fall into the trap of const vs non-const / mutable vs immutable.
You will only litter your codebase with duplicated code and terrible hacks for no real gain.
>>
>>60844587
wrong
>>
>>60844614
not wrong
>>
>>60844587

enjoy shit performance and dozens of defensive copies
>>
Am I a pro at gramming yet?
int i, j, k, d;
for (k = 0; k < n; k++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
{ d = w[i][k] + w[k][j];
if (d < w[i][j]) w[i][j] = d; }
>>
>>60844092
By the Nazis' own standards, Communism is a more successful ideology than Naziism. Naziism is an ideology for cucks who want to keep losing.

>>60844131
>t. liberal

>>60844345
Heidegger is the only one of those with any significance.
>>
>>60844642
Those only happen to shit programmers.
>>
>>60843237
Why not use iterators? They serve exactly this purpose. Range based for serves a more constrained use case.

#include <list>
#include <vector>
#include <iostream>

template<typename C, typename T>
auto find_if_index(C& c, T t) {
for (auto iter = c.begin(); iter != c.end(); ++iter) {
if (*iter == t)
return std::distance(c.begin(), iter);
}
return std::distance(c.begin(), c.end());
}

template<typename C, typename T>
void print_found(C& c, T t) {
auto val = find_if_index(c, t) ;
if (val != std::distance(c.begin(), c.end())) {
std::cout << val << '\n';
}
}

int main() {
std::vector<int> v{0, 1, 2, 3, 4};
std::list<int> l{5, 6, 7, 8, 9};

print_found(v, 3);
print_found(l, 6);
print_found(l, 3);
return 0;
}
>>
>>60844622
post an example
>>
>>60844642
>defensive copi
What is this?
Is this like where you were retarded and didn't use const so instead of going back and changing it you're retarded and just copy the object so any changes don't persist when you dispose it?
>>
>>60844644
Of course not. w isn't defined.
>>
>>60844683
Literally every time there is a const/mutable version of a function or method.

example in C++: cbegin
Example in Rust: get_mut

People think this is a sane idea. const vs mutable was a mistake.
>>
>>60844704

Yes. It's inevitable if you don't annotate your code with const.
>>
rust can't do this

for(auto &item : std::as_const(vec))
>>
>>60844734
Using const is fine, but as soon as you have to implement a const version of a function, you need to stop immediately and just settle on the least restrictive one.
>>
>>60844747
Don't compare a battle tested language to a hipster toy.
>>
>>60843127
Real question /g/ I am currently a grad student working full time as maintenance at the uni. I want to either stay here wasting time finishing MBA but eventually hit good job once I turn 26, or should I focus on learning a useful basic language like SQL just to start a better paying job which would lead to management?
>>
>>60844824
Learn Lisp.
>>
>>60844711
#define maybe_const(rettype, name, params, selfparam, body) rettype name(params, selfparam) body const rettype name(params, const selfparam) body
#define method_maybe_const(signature, body) signature body const signature const body
>>
>>60844824
Always finish your study.
>>
>>60844843
Interesting
How well does this work?
>>
>>60844824
how far into it are you? if it's just another year or so stick with it
>>
>>60844857
Pretty decently in my experience.
Example if you have class Foo and method bar that returns a pointer to an int that's a part of Foo:
method_maybe_const(int* Foo::bar(int i), {
return &my_ints[i];
})

=>
int* Foo::bar(int i) {
return &my_ints[i];
}
const int* Foo::bar(int i) const {
return &my_ints[i];
}
>>
>>60844862
>Lisp
im only at the start, like 2ish classes in, would take another 2 years to finish. I would transfer but some MBA credits dont transfer (I think). SQL is very easy, should i just take some classes and get better job and still finish?
>>
i don't really have any other ideas, so i want to just put some buttons and lights on my arduino to be able to run some scripts on my computer as basically hotkeys. i want to have a program running on my laptop and listening to the serial data from the arduino, is there an easy way to do this?
>>
>>60844886
They need to make it so this can be done with templates.
>>
>>60844906
Learn Lisp.
>>
>>60844920
Yes.
>>
How do I get better at oop? I have 0 motivation to better myself out of work. What project should I attempt?
>>
>std::byte
>A byte is only a collection of bits, and only bitwise logic operators are defined for it.

>std::optional
>There are no optional references, a program is ill-formed if it instantiates optional with a reference type.

Wow. C++17 really had the chance to redeem themselves, but they just had to fuck it all up as usual.
>>
>>60844989
video game
>>
>>60845075
C++17 is a real disappointment.
>>
>>60845075

>Using references in C++ at all, except for as const and rvalue parameters to function calls
Literally why?
>>
Hey guys, what services provide the ability to run your script in the cloud on a schedule?

Like having a script run every minute on some server even while my personal computer is turned off.

pythonanywhere seems good but you can only schedule up to 20 runs per day.
>>
>>60845138
systemd timers
>>
>>60845138
cron
>>
>>60845138
any web host that offers cloud service
>>
>>60845153
>>60845162
Yeah but I need something cloud based since I want it to run even if my computer/server is turned off.
>>
>>60845178
You know that the cloud is just a headless server, right?
>>
why does this exist in c++
float f = 14.88;

but not
Object o = new Object();

does the constructor always return a pointer or what?
>>
>>60845178
check microsoft azure, amazon aws, google cloud, maybe you can even do it for free
>>
>>60845205
thanks, that's exactly what I was looking for
>>
>>60845204
new always constructs and allocates on the heap.
If you want to construct on the stack then it's just
Object o = Object();
>>
>>60845211
lol wut
>>
>>60844988
what's the way to do it?
>>
>>60845204

>float f = 14.88;
>>>/pol/
>>
>>60845221
Use Serial.Available() first, then Serial.read().
>>
>>60845240
typo, available should be lowercase
>>
>>60845096
References give you somewhat better assertions of program state than pointers do.

But shit like:
struct SS { int& ii_; SS(int& ii) : ii_ { ii_ } { } };

should be a compile error.
>>
>>60845253
oh, and you need to call Serial.begin() before everything else to set it all up.
>>
>>60845240
>>60845253
that only works on the arduino
>>
File: 1474992776596.jpg (1MB, 2448x3264px) Image search: [Google]
1474992776596.jpg
1MB, 2448x3264px
>>60845238
>no I dont browse pol. I like my animu much more
>>
>>60845255

It should?
>>
anyone use vue.js (or any javascript frameworks) or javascript at all.

ES6 and node guys, javascript is a forced meme, but it's ok

https://vuejs.org/v2/guide/#Declarative-Rendering
https://github.com/vue-bulma/vue-admin
https://alligator.io/vuejs/rest-api-axios/

building a mock frontend for an analytics app, usually work with flask/python.
I'm thinking about making a runescape bot management system, with a vue frontend, never even really played but have a friend who is way into botting

I used to use laravel/php

anyone use RxJava?
>>
#define fn auto

fn foo() -> int {
return 9;
}

Fight me.
>>
>>60845392

lol
>>
>>60845345

It doesn't : https://godbolt.org/g/aBMzT1

It should at least generate a warning since what ends up happening is you construct a garbage reference. Initializing an object with an uninitialized object during construction seems broken.
>>
>>60845372
Thanks for the memo.
>>
I'm going to write a bit array in Python.
>>
>>60845089
I'd rather do something else.
>>
>>60845454
operating system
>>
>>60844411
How does define work.
When it takes an atom as first value, then it's defining a variable, but when its first value is a cons, then then it defines a function?
How does Scheme handle structs.
Does it even have OOP
>>
>>60845392
Functional autists BTFO. Sepples wins agains.
>>
>>60845437
What is wrong with that code exactly?
How is it uninitialized?
>>
>>60845462
magic
>>
>>60845499
Inane.
>>
>>60845450
Is this a difficult task or something
In lisp, this is just
(make-array 1234 :element-type 'bit)
>>
>>60845470
It is initializing `SS::ii_` with `SS::ii_` (not the `ii` that was passed as a parameter.) Since the memory for that instance of SS is still indeterminate that `SS::ii_` is also indeterminate. Initializing the `SS::ii_` with itself means the program is putting whatever happens to live in that memory into the `SS::ii_`
>>
>>60845517
Oh, ok.
Putting _ after or before your field names is retarded anyway.
>>
>>60845550

This. For simple ctors like this, just have the parameter be the same name as the member. It just werks.
>>
>>60844989
design patterns.
>>60844989
>What project should I attempt?
a GUI framework
>>
>>60845550
int int = (int)*(int*)int[int[int]];
>>
>>60845599

declarator syntax is shit
>>
>>60845599
Even more retarded than prepending or appending your variable names with _
>>
>>60845306
that's a sick cosplay
>>
Lmao lisp fags can't do >>60834472
>>
>>60845550
>>60845587
These are irrelevant -- it's like saying "oh, well just don't drink the tap water" in Flint.
At least clang 4.0 gives a warning though.
>>
VS Code vs Atom

Both are botnets and bloated as fuck, but which one is less shit?
>>
>>60845839
Stop being a stupid fuck and just use Vim.
>>
I couldn't be bothered to wait for C++17, so I just implemented std::optional myself
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
#include <utility>

template <typename T>
struct Option {
Option(T &&obj) {
present = true;
value() = std::move(obj);
}

Option() {
present = false;
}

bool has_value() {
return present;
}

T &value() {
assert(present);
return *reinterpret_cast<T*>(this->obj);
}

T &value_or(T &&alt) {
if (present) {
return value();
} else {
return alt;
}
}

operator bool() {
return has_value();
}

T &operator*() {
return value();
}

private:
bool present;
uint8_t obj[sizeof(T)];
};

Option<int> foo() {
return 1245;
}

int main() {
if (auto val = foo()) {
printf("Have value %i\n", *val);
}
}


But I have no idea how you would implement std::variant.
>>
>>60845880
Disgusting.
>>
>>60845844
I am a plebian piece of shit and need muh autocomplete. It's a bitch to install on vim though.
Shitty IDE editors and vim plugins is the white man's choice.
>>
>>60845880
nice. I hate when retards complain some language doesn't have a feature but forget that it can be implemented in 30 lines and imported whenever you need it.
>>
>>60845880
You have some potential alignment problems here.
Put `present` below `obj` and use `alignas(T)` on obj.
>>
>>60845953
>Put `present` below `obj`
Why?
>and use `alignas(T)` on obj.
How?
>>
>>60845880

>But I have no idea how you would implement std::variant.
a struct containing union and an enum?
>>
>>60845968
> Why?
Memory layout is based on declaration order. uint8_t is byte aligned. Most objects are word aligned.
> How?
you can do like `alignas(T) uint8_t obj[sizeof(T)];` to force alignment for the array to be the same as for T.
>>
>>60845880
I got these errors when I treid to compile. I dont program in c++ so I have no idea what i'm doing. What am I doing wrong?
$ g++ option.c
option.c:8:14: error: expected ‘,’ or ‘...’ before ‘&&’ token
Option(T &&obj) {
^
option.c:26:19: error: expected ‘,’ or ‘...’ before ‘&&’ token
T &value_or(T &&alt) {
^
option.c: In constructor ‘Option<T>::Option(T)’:
option.c:10:19: error: ‘move’ is not a member of ‘std’
value() = std::move(obj);
^
option.c: In member function ‘T& Option<T>::value_or(T)’:
option.c:30:20: error: ‘alt’ was not declared in this scope
return alt;
^
option.c: In function ‘int main()’:
option.c:52:9: error: decl-specifier invalid in condition
if (auto val = foo()) {
^
option.c:53:36: error: invalid type argument of unary ‘*’ (have ‘int’)
printf("Have value %i\n", *val);
^
>>
>>60846005
And how would you generate the variants with templates?
How would you find the maximum size among the types?
>>
Is it better to use `(,var1 ,var2 ...) or (list var1 var2 ...)
>>
>>60846024
I usually see the first in macros, and the second everywhere else.
>>
>>60846012
rename the file to option.cc or option.cxx or option.cpp.
also pass in -std=c++14 as a command line flag.
>>
>>60845949
I feel like vs code is less bloated desu, faster and has more features, they managed to get electron somewhat optimized. Ms dev department has always been sorta good
>>
>>60846038
that did it, thanks
>>
>>60846017

>How would you find the maximum size among the types?
automatically taken care of with the union
>>
>>60846055
Oh ok, for some reason I missed where you said union.
But what about the enum? How would you generate the variants for that?
How would you make it type safe?
Something tells me that std::variant uses RTTI.
>>
>>60846087
The obvious way to me just seems to have an additional int that indicates which of the template parameters is currently being held by the union.
>>
Behold: the only data type you should ever need.
struct datum {
enum { DNIL, DINT, DDOUB, DARR, DSTR, DFPTR, } tag;
union {
int integer;
double decimal;
struct {
void* begin;
size_t size; /* in chars */
} array;
void* string; /* null term */
struct datum (*function)(struct datum);
} as;
};
>>
>>60846087
It looks like std::variant uses a bi-directional type index and matches against that. So the class template takes a list of accepted types, and as part of that constructs an index that allows to map types to index or index to types, and everything outside of those ranges dies. Additionally it stores a runtime index value that can map to currently stored type.
>>
Speaking of text editors, how do people usually program in C/C++ on linux? Isn't using gdb in vim a pain in the ass compared to hitting f8 in vstudio, not trying to start a fight, looking for a good setup
>>
>>60846145
Sounds inefficient as fuck compared to rust enums (tagged unions).
>>
>>60846155
I use vim and gdb (gdb tui mode is pretty OK if you're careful with it.) DDD is also an interesting option but it requires a ridiculously huge monitor.
>>
>>60846155
Things that make it less painful:
>build scripts
>terminal multiplexers
There are also comfier and more hand-holdy IDEs you can find in the various app-store-like graphical repository browsers out there, if that's what you're used to and you're not ready to dive headfirst into the 90's.
>>
>>60846140
That can use some cleanup, though.
struct datum {
enum { D_NIL, D_INT64, D_F64, D_ARR, D_STR, D_FPTR } tag;
union {
int64_t i64;
double f64;
struct {
void *begin;
size_t size;
} array;
char *string;
struct datum (*function)(struct datum);
};
};
>>
File: 1497116785673.gif (645KB, 969x700px) Image search: [Google]
1497116785673.gif
645KB, 969x700px
they say you should learn a new language every 6 months. what language have you most recently learned or started learning anons?
>>
>>60846169
Literally exactly the same thing. C++ just uses template metaprogramming and constexprs to generate the language feature for the set of acceptable types. I will admit tagged unions as an actual language feature are superior for generating diagnostics.
>>
>>60846155
https://www.jetbrains.com/clion/
>>
>>60846213
>Literally exactly the same thing
No.
C++ variants have to store a fucking lookup table with them.
Rust enums just have a single discriminant (an integer) to match against, with values decided on by compiler.
>>
>>60846209
haven't learn anything since i have learned a lisp (racket).

>>60846209
>they say you should learn a new language every 6 months.
who "they"?
>>
>>60846209
Chapel.
>learn a new language every 6 months
I ques it makes sense to check if there's something new and interesting but otherwise it makes no sense when C is still the only usable language.
>>
>>60846209
C++
>>
>>60846205
Looks mostly better, except that int64s may be less efficient than ints (maybe put both?) and also using a union type with no associated variable like that is nonstandard
>>
>>60846284
anonymous structures and unions are standard
>>
>>60846284
>except that int64s may be less efficient than ints
You have the space of a double/pointer. You may as well make the types all the same size (excluding array in this case.
Also, this makes it basically compatible with JSON types and a lot of other serialisation formats.
>and also using a union type with no associated variable like that is nonstandard
No, they're C11 anonymous structs/unions.
>>
>>60846284
>>60846308
see
http://port70.net/~nsz/c/c11/n1570.html#6.7.2.1
>>
>>60843127
I'm still caught up with C++ polymorphism.

Why doesn't animals[0]->talk() call Dog's member function?
>>
>>60846247
Ah, gotcha. So rust guarantees unique type ids across an entire program? I wish C++ could do the same thing.

That said, in C++ variant the lookup table lives in code only, though each variant template has its own.
>>
>>60846326
because talk() is not virtual. animals[0] being of type Animal, Animal::Talk() is call.
>>
>>60846352
!! Thanks Boss.
>>
>>60846381
Don't call me Boss. Call me Fuhrer.
>>
>>60846347
>So rust guarantees unique type ids across an entire program?
Yes.

>in C++ variant the lookup table lives in code only
What do you mean?
>>
>>60846410
With that, if I place the reference to my dog object in my vector, do I need to maintain the objects as long as the vector exists?

would I be able to
vector.push_back(new Dog(d));
and have the objects exist independently in the vector? Once I create the copy constructor.
>>
Why doesn't C have strong typedefs?
>>
File: 1497134504268.jpg (12KB, 258x245px) Image search: [Google]
1497134504268.jpg
12KB, 258x245px
>rust doesn't have a C-style for loop
>>
>>60846476
Because C programmers don't give a fuck about safety or sanity.
>>
>>60846322
>You have the space of a double/pointer. You may as well make the types all the same size (excluding array in this case.
>Also, this makes it basically compatible with JSON types and a lot of other serialisation formats.
Oh right. ye definitely

>>60846322
>No, they're C11 anonymous structs/unions.
>>60846308
>>60846323
Yeah but what about c89
c89 is my target standard, i program everything in it
... do i have a problem?
>>
>>60846476
What do you maen with strong typedefs?
>>
>>60846498
Does Rust have strong typedefs, then?
>>
>>60846482
Rust does not have the “C-style” for loop on purpose. Manually controlling each element of the loop is complicated and error prone, even for experienced C developers.
>>
>>60846527
t. brainlet
>>
>>60846512
Use the latest C standard, idiot.
There is no legitimate reason not to.
>>
>>60846515
typedefs to the same base type that are not considered compatible types to each other.
>>
>>60846473
>would I be able to
>vector.push_back(new Dog(d)); and have the objects exist independently in the vector? Once I create the copy constructor.
Yes, that's the point of a copy constructor. However, you would have to make sure to delete them independently as well.
>>
>>60846140
>Behold: the only data type you should ever need.
Clunky if I ever want to put a bignum in it. OTOH, you've got raw pointers for the array contents and string fields.

I'd give it 3/5. Not a terrible attempt, but Could Do Better. Wouldn't touch in my own code.
>>
>>60846527
you think a language without a traditional for loop will replace C++ in the foreseeable future?
>>
>>60846421
The lookup table lives in the .text section of your program, not the .data or .bss. Each std::variant specialization is its own type. Each specialization has its own lookup table that may (or may not be) optimized. Each instance of a given specialization refers to the SAME lookup table (which is code -- a function call.)
>>
>>60846545
ok thanks Fuhrer.
>>
>>60846541
But then my code can't be compiled on computers from 1989.
>>
>>60846209
Lua
>>
>>60846473

In this >>60846326 example, the pointer will remain valid until the function main finishes. When main exits, the Dog d is destructed, and the pointer is invalid.
If you want the vector to outlive main, then you should use new to create a new Dog outside of the scope of main. While you're learning, anyway. Remember that every pointer you new needs to be deleted at some point, or else you have a memory leak.
>>
>>60846527
>Rust does not have the “C-style” for loop on purpose.
Does it have while loops? If not, it's a toy. If it does, it's just a trivial macro away from something that works like a C for loop. Also, I don't need an official macro language in order to graft a macro system on front of something.
>>
>>60846482
dumb frogposter
>>
>>60846551
Rust supports range-based for loops, which provide a cleaner syntax for the most common use case of C-style for loops. While there are other things you can do with C-style for loops, iterating over a range is so common that any type somebody sees the for keyword, they assume that's what's being done, which leads to errors and poor readability. It's better to reserve the for keyword for range-based loops and be more explicit when another form of control flow is being used.
>>
Working on my internet stealing and secure tunneling software.

Adding documentation to the library I wrote to parse/build network packets using an ergonomic API.

This is what the API looks like, I wish I could avoid returning Result<Self> from builder methods but errors could arise from passing out-of-range values in cases where the value is less than 8 bits, or when using a static buffer and the builder tries to allocate more space than what the static buffer can contain.

let packet = ether::Builder::default()
.destination("00:23:69:63:59:be".parse()?)?
.source("e4:b3:18:26:63:a3".parse()?)?
.ip()?.v4()?
.id(0x2d87)?
.ttl(64)?
.source("66.102.1.108".parse()?)?
.destination("192.168.0.79".parse()?)?
.udp()?
.source(1337)?
.destination(9001)?
.build()?;

let ether = ether::Packet::new(packet)?;
assert_eq!(ether.destination(), "00:23:69:63:59:be".parse()?);
assert_eq!(ether.source(), "e4:b3:18:26:63:a3".parse()?);
assert_eq!(ether.protocol(), ether::Protocol::Ipv4);

let ip = ip::v4::Packet::new(ether.payload())?;
assert_eq!(ip.id(), 0x2d87);
assert!(ip.flags().is_empty());
assert_eq!(ip.length(), 28);
assert_eq!(ip.ttl(), 64);
assert_eq!(ip.protocol(), ip::Protocol::Udp);
assert_eq!(ip.source(), "66.102.1.108".parse::<Ipv4Addr>()?);
assert_eq!(ip.destination(), "192.168.0.79".parse::<Ipv4Addr>()?);
assert!(ip.is_valid());

let udp = udp::Packet::new(ip.payload())?;
assert_eq!(udp.source(), 1337);
assert_eq!(udp.destination(), 9001);
assert!(udp.is_valid(&ip::Packet::from(&ip)));
>>
>>60846592
>If it does, it's just a trivial macro away from something that works like a C for loop.
A trivial and also useless macro, one might add. "For" is properly intended for iterating over a container. If the data you're iterating over does not consist of keys to a container, you should be using while; to do otherwise convolutes your intention.
>>
/dpt/ why are there so many languages with first class functions but so few languages with first class types? ruby and javascript are the only ones i know and in javascript they aren't even types, they're just constructors.
>>
>>60846720

>javascript
>constructor
>>
>>60846729
Well, that's what they are. They're certainly not classes, although people use them that way.
>>
>>60846720
python has first class objects, and everything's an object. i'm now sure how you'd have first class "types"
>>
File: 34.gif (17KB, 300x100px) Image search: [Google]
34.gif
17KB, 300x100px
>>60843127
Working on my imageboard, 4kev.org
>>
>>60846738
Make types objects :V
>>
>>60846720
Common Lisp types are classes.
>>
>>60846720
Java
https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html
Python
https://stackoverflow.com/questions/4479819/types-and-classes-in-python
CL
http://clhs.lisp.se/Body/f_tp_of.htm
>>
>https://medium.com/@johnnylin/how-to-make-80-000-per-month-on-the-apple-app-store-bdb943862e88
>lmao
so I get that I should start programming asap
>>
>>60846738
>i'm now sure how you'd have first class "types"
here an example in python

https://ideone.com/jmT7Nt

def new(type,init_value):
return type(init_value)

a = 1234
b = type(a) # get type of a
c = new(b, 456)

print(c)
print(b)
>>
>>60846784
ah i see what you mean now. still don't see why you'd want to do that
>>
>>60846738
here's an example of it in ruby
class MyType; end
puts MyType.class # outputs "Class"
mt = MyType.new # "new" is implemented as an instance method of Class

classes in ruby can also have their own state and method independently from their instances; this is not "static" data, because the class is an object, so it's just properties of the object that is the class
class MyType
class << self # defines "singleton class" in-between this object and super on the inheritance chain; pretty much just a way to put extra functionality onto an object without making a subclass
def doTheThing
puts self.new.class
end
end
end
MyType.doTheThing # outputs "MyType"

can python do that?
>>
>>60846804
Vaguely related is dependent types -- see Idris. Being able to perform computations on types allows you to generate specific programs over those types, which allows a more declarative syntax for describing a program.
>>
>>60846804
a typed list for example

class TypeList(list):
def __init__ (self, elementType):
self.elementType = elementType

def append(self, element):
if type(self != self.elementType)
raise exception types don't match
return super().append(element)

a = TypeList(Int)

a.append(123) # ok
a.append("123") # error
>>
>>60846782
jesus christ
>>
https://slapbot.github.io/documentation/configuration/
>gender - Well, this is quite basic, should I continue this? I wonder.
uh oh
>>
>>60846930
literally shaking
>>
>>60846930
>city - The city in which your mom lives in.
kek
>>
>>60846841
it's just python's dynamically typed anyways so that example doesn't really mean anything more than returning init_value rather than type(init_value)
>>60846834
>ruby
i don't use languages made for traps
>>
>>60846930
I don't get it. You seem to be suggesting there are people who would take issue with the claim that it's a pretty basic concept to type whatever you want into the gender field in a config file, including things other than "male" or "female" if you feel compelled to do so. There pretty much aren't.
>>
>>60846967
>i don't use languages made for traps
Aw, you don't?
I do. And yet I remain squarely masculine.
It's truly disheartening. All I ever wanted was to be the little girl.
>>
>>60846967
>doesn't really mean anything more than returning init_value rather than type(init_value)

wrong, for example,

new(string, 123) -> "123"
new(int, "123") -> 123
>>
New thread: >>60847014
>>
>>60847011
then you're not using it as a type, you're using it to do class instantiation and are passing a class initializer
>>
>>60846979
                gender = self.gender.lower()
if gender == "male":
return "%s, sir!" % self.phase_of_the_day(t)
elif gender == "female":
>>
>>60847043
 "{}s, sir!".format(self.phase_of_the_day(t))
>>
>>60847043
Where's the rest of your code?
>>
>>60844411
lmao
(defvar philosophers
'(john jack sam michael ed))
>>
New thread:
>>60847211
>>60847211
>>60847211
>>
>>60847172
that was just the github search result

the code has the return statement duplicated with "sir" on male/female/other
>>
>>60843145
You can implement a custom container to do that in C++17.
>>
>>60847455

C++17 is only important for automatically tying the tuple to variables. It's not hard to build a general purpose enumerator class that boxes a classic iterator, which then lets you write something like this.
for (auto [n, i] : iter_enum(vec)
{
// do your shit
}
>>
>>60843152
>pepe
>reddit
Hello newfag
>>
Where would one find pictures/animations for their apps?
>>
>>60848518
Clipart
>>
>>60848525
Thanks famalama
Thread posts: 325
Thread images: 23


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.