<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n" -->

---
title: Branchless sorting of trivially relocatable types
description: Arthur O&#x27;Dwyer explores how to extend the branchless quicksort library blqsort to work efficiently with trivially relocatable types (like shared_ptr), not just...
canonical: https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Branchless sorting of trivially relocatable types | daily.dev
og:description: Arthur O&#x27;Dwyer explores how to extend the branchless quicksort library blqsort to work efficiently with trivially relocatable types (like shared_ptr), not just...
og:url: https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n
og:image: https://api.daily.dev/og/posts/wkK1FDG6n.png
og:image:alt: Branchless sorting of trivially relocatable types
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Branchless sorting of trivially relocatable types

**[Arthur O'Dwyer](https://daily.dev/sources/quuxplusone)** · 9 min read · 0 upvotes · 0 comments

## Summary

Arthur O'Dwyer explores how to extend the branchless quicksort library blqsort to work efficiently with trivially relocatable types (like shared_ptr), not just trivially copyable ones. The key insight is that sorting is an affine, one-to-one permutation of values, so the entire algorithm can operate on raw byte representations when T is trivially relocatable. An eight-line patch reinterprets T objects as aligned byte blocks (Rep), enabling the branchless fast path for types like shared_ptr. Benchmarks on 50 million elements show this turns a 4% win into a 38% win for shared_ptr-like types. The post also discusses the type-punning UB involved, the P1144/P3516 relocate_at alternative, and the current state of compiler support for is_trivially_relocatable in Clang and GCC.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://quuxplusone.github.io/blog/2026/06/05/branchless-sorting>

## Similar posts on daily.dev

- [Branchless Quicksort](https://daily.dev/posts/branchless-quicksort-lqrg1x2cu) · Lobsters · 1 upvotes · 0 comments
- [Thoughts on P3858R0 restart\_lifetime<T>](https://daily.dev/posts/thoughts-on-p3858r0-restart-lifetime-t--zfiryrnba) · Arthur O'Dwyer · 0 upvotes · 0 comments
- [A dialogue on trivial-abi and trivially relocatable](https://daily.dev/posts/a-dialogue-on-trivial-abi-and-trivially-relocatable-d2elgvd6z) · Arthur O'Dwyer · 0 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Branchless sorting of trivially relocatable types","url":"https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n"},"datePublished":"2026-06-05T18:09:56.201Z","dateModified":"2026-06-05T18:10:19.051Z","description":"Arthur O'Dwyer explores how to extend the branchless quicksort library blqsort to work efficiently with trivially relocatable types (like shared_ptr), not just...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3a9783d2dc46301158849c96a3b989b?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e3a9783d2dc46301158849c96a3b989b?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Arthur O'Dwyer","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Arthur O'Dwyer","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a789aa2fcdb64c219980d6d6901791e9","url":"https://daily.dev/sources/quuxplusone"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/branchless-sorting-of-trivially-relocatable-types-wkk1fdg6n","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,c++","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Arthur O'Dwyer","item":"https://daily.dev/sources/quuxplusone"},{"@type":"ListItem","position":3,"name":"Branchless sorting of trivially relocatable types"}]}
```

