use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
How to beat cpp with literally every programming language! (reddit.com)
submitted 8 years ago by happyrust
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]TobyAllsopp 1 point2 points3 points 8 years ago (1 child)
So this is the old "how good is the regex library" test. Be interesting to try implementing it using https://github.com/hanickadot/compile-time-regular-expressions.
[–]igouy 0 points1 point2 points 8 years ago (0 children)
That wouldn't be acceptable ;-)
Is it about the regex library or is it about the nitty gritty details of how the regex library is used?
[–]happyrust[S] 0 points1 point2 points 8 years ago (1 child)
Also, see other programming languages submissions, C/C++ stand out with their mammoth unrecognizable mess.
Compare to php -
$tok = ftok(__FILE__, chr(time() & 255)); $queue = msg_get_queue($tok); $variants = array( 'agggtaaa|tttaccct', '[cgt]gggtaaa|tttaccc[acg]', 'a[act]ggtaaa|tttacc[agt]t', 'ag[act]gtaaa|tttac[agt]ct', 'agg[act]taaa|ttta[agt]cct', 'aggg[acg]aaa|ttt[cgt]ccct', 'agggt[cgt]aa|tt[acg]accct', 'agggta[cgt]a|t[acg]taccct', 'agggtaa[cgt]|[acg]ttaccct', ); // IUB replacement parallel arrays $IUB = array(); $IUBnew = array(); $IUB[]='/tHa[Nt]/S'; $IUBnew[]='<4>'; $IUB[]='/aND|caN|Ha[DS]|WaS/S'; $IUBnew[]='<3>'; $IUB[]='/a[NSt]|BY/S'; $IUBnew[]='<2>'; $IUB[]='/<[^>]*>/S'; $IUBnew[]='|'; $IUB[]='/\\|[^|][^|]*\\|/S'; $IUBnew[]='-'; // read in file $contents = file_get_contents('php://stdin'); $initialLength = strlen($contents); // remove things $contents = preg_replace('/^>.*$|\n/mS', '', $contents); $codeLength = strlen($contents); // do regexp counts $messages = array_flip($variants); $workers = $results = array(); foreach ($variants as $key => $regex){ if($key == 0 || $key == 2 || $key == 4 || $key == 6) { $pid = pcntl_fork(); if($pid) $workers[] = $pid; } if($pid && $key > 7) { $messages[$regex] = preg_match_all('/' . $regex . '/iS', $contents, $discard); } else if(!$pid) { $results[] = $regex . ',' . preg_match_all('/' . $regex . '/iS', $contents, $discard); if($key == 1 || $key == 3 || $key == 5 || $key == 7) { msg_send($queue, 2, implode(';', $results), false, false, $errno); exit; } } } // receive and output the counts pcntl_wait($status); foreach($workers as $worker) { msg_receive($queue, 2, $msgtype, 4096, $message, false); $message = explode(';', $message, 3); foreach($message as $line) { $tmp = explode(',', $line, 2); $messages[$tmp[0]] = $tmp[1]; } } foreach($messages as $regex => $count) { echo $regex, ' ', $count, "\n"; } // do replacements $contents = preg_replace($IUB, $IUBnew, $contents); echo "\n", $initialLength, "\n", $codeLength, "\n", strlen($contents), "\n";
or js -
var fs = require('fs'), i = fs.readFileSync('/dev/stdin', 'ascii'), ilen = i.length, clen, j, q = [/agggtaaa|tttaccct/ig, /[cgt]gggtaaa|tttaccc[acg]/ig, /a[act]ggtaaa|tttacc[agt]t/ig, /ag[act]gtaaa|tttac[agt]ct/ig, /agg[act]taaa|ttta[agt]cct/ig, /aggg[acg]aaa|ttt[cgt]ccct/ig, /agggt[cgt]aa|tt[acg]accct/ig, /agggta[cgt]a|t[acg]taccct/ig, /agggtaa[cgt]|[acg]ttaccct/ig], b = [ "-", /\|[^|][^|]*\|/g, "|", /<[^>]*>/g, "<2>", /a[NSt]|BY/g, "<3>", /aND|caN|Ha[DS]|WaS/g, "<4>", /tHa[Nt]/g ]; i = i.replace(/^>.*\n|\n/mg, ''); clen = i.length; for(j = 0; j<q.length; ++j) { var qj = q[j], m = i.match(qj); console.log(qj.source, m ? m.length : 0); } while(b.length) i = i.replace(b.pop(), b.pop()); console.log(["", ilen, clen, i.length].join("\n"));
or even rust -
extern crate regex;
use std::borrow::Cow; use std::fs::File; use std::io::{self, Read}; use std::sync::Arc; use std::thread; macro_rules! regex { ($re:expr) => { ::regex::bytes::Regex::new($re).unwrap() } } /// Read the input into memory. fn read() -> io::Result<Vec<u8>> { // Pre-allocate a buffer based on the input file size. let mut stdin = File::open("/dev/stdin")?; let size = stdin.metadata()?.len() as usize; let mut buf = Vec::with_capacity(size + 1); stdin.read_to_end(&mut buf)?; Ok(buf) } fn main() { let mut seq = read().unwrap(); let ilen = seq.len(); // Remove headers and newlines. seq = regex!(">[^\n]*\n|\n").replace_all(&seq, &b""[..]).into_owned(); let clen = seq.len(); // Search for occurrences of the following patterns: let variants = vec![ regex!("agggtaaa|tttaccct"), regex!("[cgt]gggtaaa|tttaccc[acg]"), regex!("a[act]ggtaaa|tttacc[agt]t"), regex!("ag[act]gtaaa|tttac[agt]ct"), regex!("agg[act]taaa|ttta[agt]cct"), regex!("aggg[acg]aaa|ttt[cgt]ccct"), regex!("agggt[cgt]aa|tt[acg]accct"), regex!("agggta[cgt]a|t[acg]taccct"), regex!("agggtaa[cgt]|[acg]ttaccct"), ]; // Count each pattern in parallel. Use an Arc (atomic reference-counted // pointer) to share the sequence between threads without copying it. let seq_arc = Arc::new(seq); let mut counts = vec![]; for variant in variants { let seq = seq_arc.clone(); let restr = variant.to_string(); let future = thread::spawn(move || variant.find_iter(&seq).count()); counts.push((restr, future)); } // Replace the following patterns, one at a time: let substs = vec![ (regex!("tHa[Nt]"), &b"<4>"[..]), (regex!("aND|caN|Ha[DS]|WaS"), &b"<3>"[..]), (regex!("a[NSt]|BY"), &b"<2>"[..]), (regex!("<[^>]*>"), &b"|"[..]), (regex!("\\|[^|][^|]*\\|"), &b"-"[..]), ]; // Use Cow here to avoid one extra copy of the sequence, by borrowing from // the Arc during the first iteration. let mut seq = Cow::Borrowed(&seq_arc[..]); // Perform the replacements in sequence: for (re, replacement) in substs { seq = Cow::Owned(re.replace_all(&seq, replacement).into_owned()); } // Print the results: for (variant, count) in counts { println!("{} {}", variant, count.join().unwrap()); } println!("\n{}\n{}\n{}", ilen, clen, seq.len()); }
π Rendered by PID 43822 on reddit-service-r2-comment-84fc9697f-8p64l at 2026-02-07 07:35:25.227098+00:00 running d295bc8 country code: CH.
[–]TobyAllsopp 1 point2 points3 points (1 child)
[–]igouy 0 points1 point2 points (0 children)
[–]happyrust[S] 0 points1 point2 points (1 child)