// a sample program using concepts // tested in gcc and clang template <typename T> concept has_a = requires(T v) { v.a(); }; template <typename T> requires has_a<T> void fun(T v) { v.a(); }| godbolt.org
template <typename T> struct wrapper { T _value; void operator() () requires std::is_invocable_v<T> { _value(); } void reset(T v) { _value = v; } }; // explicit instantiation: template struct wrapper<int>;| godbolt.org
Compiler Explorer is an interactive online compiler which shows the assembly output of compiled C++, Rust, Go (and many more) code.| godbolt.org
bool is_leap_year3(uint32_t y) { return (y & ((y % 25) ? 3 : 15)) == 0; }| godbolt.org
bool is_leap_year1(uint32_t y) { if ((y % 4) != 0) return false; if ((y % 25) != 0) return true; if ((y % 16) == 0) return true; return false; }| godbolt.org
#[no_mangle] pub fn compare256(src0: &[u8; 256], src1: &[u8; 256]) -> usize { src0.iter().zip(src1).take_while(|(x, y)| x == y).count() }| godbolt.org
use std::arch::x86_64::*; #[no_mangle] #[target_feature(enable = "sse2,bmi1")] pub unsafe fn compare256(src0: &[u8; 256], src1: &[u8; 256]) -> usize { let src0 = src0.chunks_exact(16); let src1 = src1.chunks_exact(16); let mut len = 0; unsafe { for (chunk0, chunk1) in src0.zip(src1) { // load the next chunks into a simd register let xmm_src0 = _mm_loadu_si128(chunk0.as_ptr() as *const __m128i); let xmm_src1 = _mm_loadu_si128(chunk1.as_ptr() as *const __m128i); // element-wise compare of the 8...| godbolt.org