AoC day 5. Part 1 was straightforward; the naive solution that checks every ID against every range is plenty fast. For part 2 I went with a three-step approach: Read provided ranges, merge adjacent/overlapping ranges, sum up the remaining (non-overlapping) ranges.

use v5.36;
use List::Util qw(sum0 min);

my @ranges;
while (readline) {
chomp;
last if $_ eq '';

my ($lo, $hi) = m{^ (\d+) - (\d+) \z}xa
or die "bad input: '$_'";

push @ranges, [$lo, $hi + 1];
}

@ranges = sort { $a->[1] <=> $b->[1] } @ranges;

for my $i (reverse 1 .. $#ranges) {
if ($ranges[$i - 1][1] >= $ranges[$i][0]) {
$ranges[$i - 1][1] = $ranges[$i][1];
$ranges[$i - 1][0] = min $ranges[$i - 1][0], $ranges[$i][0];
splice @ranges, $i, 1;
}
}

say sum0 map $_->[1] - $_->[0], @ranges;

#AdventOfCode #perl

🌘 C++26:std::optional 的範圍(range)支援
➤ 為 std::optional 注入範圍語彙,打造更簡潔的 C++ 程式碼
https://www.sandordargo.com/blog/2025/10/08/cpp26-range-support-for-std-optional
C++26 將為 std::optional 引入範圍(range)的支援,這項重大更新讓 std::optional 的物件本身也能作為一個最多隻包含一個元素的範圍來使用。此功能極大地簡化了在組合式程式碼中處理可能不存在的值的邏輯,能夠無縫整合至現有的範圍管線中,自動略過空值,無需手動進行 if 檢查,從而提升了程式碼的可讀性與效率。
+ 這個改動太棒了!再也不用寫一堆 `if (opt)` 了,直接用 range-based for loop 處理,程式碼瞬間清爽很多。
+ 一開始覺得這有點多餘,但看到 P3168R2 的範例後,發現它在處理連續的 range 操作時,確實能大幅減少樣板程
#C++ #C++26 #std::optional #Ranges #STL
C++26: range support for std::optional

I learned about the new range API of std::optional from Steve Downey at CppCon 2025 during his talk about std::optional<T&>. To be honest, I found the idea quite strange at first. I wanted to dig deeper to understand the motivation and the implications. The first example I encountered was this: 1 2 3 4 5 6 7 void doSomething(std::string const& data, std::optional<Logger&> logger = {}) { for (auto l : logger) { l.log(data); } return; } This shows that you can iterate over an optional. In fact, iterating over an optional means the loop will execute either zero or one time. That’s neat — but at first glance, you might ask: why on Earth would anyone want to do that? After all, you could just write: 1 2 3 4 5 6 7 void doSomething(std::string const& data, std::optional<Logger&> logger = {}) { if (logger.has_value()) { l->log(data); } return; } Sure, you need pointer semantics, but if you dislike the arrow operator, you can write logger.value().log(data). It’s slightly longer, but arguably more expressive. So what’s the real value of the range-based approach? Well, the people writing the standard are not exactly known for adding features “just because” - they are smart and considerate. I figured there had to be more compelling examples that didn’t fit into a presentation slide. And indeed, there are. When optional Meets Ranges A great use case appears when chaining ranges involving optional values. The range API allows us to avoid explicit null checks in pipelines where missing values are simply skipped. Here’s an example from P3168R2: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // Example from P3168R2: start from a set of values, apply multiple range operations involving optional values. std::unordered_set<int> s{1, 3, 7, 9}; const auto flt = [&](int i) -> std::optional<int> { if (s.contains(i)) { return i; } else { return {}; } }; for (auto i : std::views::iota(1, 10) | std::views::transform(flt)) { for (auto j : i) { // no need to transform for (auto k : std::views::iota(0, j)) { // std::cout << '\a'; // do not actually log in tests std::ignore = k; } // std::cout << '\n'; // do not actually log in tests } } This is where std::optional as a range truly shines — it integrates seamlessly into the range pipeline and eliminates manual if checks. You can find a broader set of examples in the Beman project unit tests . Competing Proposals Interestingly, there were competing proposals for this functionality. P1255R12 suggested two new views: views::maybe and views::nullable. The former would have represented a view holding zero or one value, while the latter would have adapted types that may or may not contain a value. However, the authors of P3168R2 argued for a simpler, more unified approach. Since std::optional and the proposed maybe_view used identical wording: “may or may not store a value of type T”, introducing another type with the same semantics seemed redundant. In the end, genericity and simplicity won — we didn’t need a new view when optional could just become one. You can read the arguments pro and contra in the referenced papers. std::optional as a View By adopting this range interface, std::optional effectively becomes a view containing at most one element. The question was how to make it so. Two options were considered: Inheriting from std::ranges::view_interface<std::optional<T>> Specializing std::ranges::enable_view<std::optional<T>> to true The first approach would have introduced unnecessary member functions, contradicting the simplicity goal. So the second option won — std::optional<T> now simply specializes ranges::enable_view in the same spirit as std::string_view and std::span. Iterator Types The authors really believe in simplicity. They kept trimming unnecessary parts between revisions. Initially, they considered defining a full suite of iterator algorithms, but realized that the existing ranges::begin(), ranges::cbegin(), et al. already do a big part of the job. As a result, std::optional only defines iterator and const_iterator, both of which are implementation-defined. They were originally meant to be raw pointers, but that could have led to misuse — such as applying placement new — so implementers will need to ensure safer behavior. Conclusion std::optional’s new range interface might look unusual at first, but it’s a subtle, useful enhancement. It integrates optional into the range ecosystem, letting it compose cleanly with other views and transformations without explicit branching. Rather than introducing yet another view type, the committee went with keeping things simple and making existing abstractions more composable. It might take a while to feel natural, but once you start thinking of optional as “a range of at most one”, it all clicks. Connect deeper If you liked this article, please hit on the like button, subscribe to my newsletter and let’s connect on Twitter!

Sandor Dargo’s Blog
Some more grey sky lines . gentle rain on the tin roof kind of day #clouds #skyscape #landscape #australia #rainy #days in the #ranges
Dec 9 2021 amazing clouds above the Border Ranges . NE NSW #clouds #epic #mountains #ranges #countrylife #bundjalungcountry #australia #landscape #skyscape

Love this City: Love the Waitākere Ranges! – Simon Wilson

Harrumph, say NZ First’s Shane Jones and Hobson’s Pledge. They call it “co-governance”. But that wasn’t how most…
#NewsBeep #News #Headlines #auckland #city #events #exploring #ideas #love #makaurau #NewZealand #newsletter #NZ #potential #ranges #reality #simon #the #this #tmaki #transcript #waitkere #Weekly #wilson #wilsons
https://www.newsbeep.com/63635/

I have just published the first release of my experimental C++ Ranges library:

📡 ℝange 𝔸𝕕aptors ℝeimagined 📡
https://github.com/h-2/radr

Go check it out!

#cplusplus #cpp #ranges #programming

Govt to increase Crown body board members’ fee ranges by up to 80%

At last year’s Budget, it promised working-age New Zealanders would benefit on average by $16 a week from…
#NewsBeep #News #Headlines #80 #agreed #board #bodies #body #by #cases #could #crown #fee #fees #Government #govt #increase #members #NewZealand #NZ #paid #quietly #raise #range #ranges #some #to #up
https://www.newsbeep.com/23863/

Встреча ISO C++ в Софии: С++26 и рефлексия

Привет! На связи Антон Полухин из Техплатформы Городских сервисов Яндекса, и сейчас я расскажу о софийской встрече Международного комитета по стандартизации языка программирования C++, в которой принимал активное участие. Это была последняя встреча, на которой новые фичи языка, с предодобренным на прошлых встречах дизайном, ещё могли попасть в C++26. И результат превзошёл все ожидания: compile-time-рефлексия рефлексия параметров функций аннотации std::optional<T&‍> параллельные алгоритмы Об этих и других новинках расскажу в посте

https://habr.com/ru/companies/yandex/articles/920470/

#c++29 ++29 #c++26 ++26 ++ #c++ #reflection #constexpr #exception #simd #safety #security #undefined_behavior #annotations #parallel_programming #executor #executors #ranges #coroutines

Встреча ISO C++ в Софии: С++26 и рефлексия

Привет! На связи Антон Полухин из техплатформы городских сервисов Яндекса, и сейчас я расскажу о софийской встрече Международного комитета по стандартизации языка программирования C++, в которой...

Хабр

Встреча ISO C++ в Софии: С++26 и рефлексия

Привет! На связи Антон Полухин из техплатформы городских сервисов Яндекса, и сейчас я расскажу о софийской встрече Международного комитета по стандартизации языка программирования C++, в которой принимал активное участие. Это была последняя встреча, на которой новые фичи языка, с предодобренным на прошлых встречах дизайном, ещё могли попасть в C++26. И результат превзошёл все ожидания: compile-time-рефлексия рефлексия параметров функций аннотации std::optional<T&‍> параллельные алгоритмы Об этих и других новинках расскажу в посте

https://habr.com/ru/companies/yandex/articles/920470/

#c++29 ++29 #c++26 ++26 ++ #c++ #reflection #constexpr #exception #simd #safety #security #undefined_behavior #annotations #parallel_programming #executor #executors #ranges #coroutines

Встреча ISO C++ в Софии: С++26 и рефлексия

Привет! На связи Антон Полухин из техплатформы городских сервисов Яндекса, и сейчас я расскажу о софийской встрече Международного комитета по стандартизации языка программирования C++, в которой...

Хабр

C++OnSea 2025 SESSION ANNOUNCEMENT: Missing (and future?) C++ Range Concepts by @foonathan

https://cpponsea.uk/2025/session/missing-and-future-cpp-range-concepts

Register now at https://cpponsea.uk/tickets/

#algorithms #cplusplus #cpp #ranges

C++ on Sea