Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

saturate_cast

オープン
#200 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp
領域
tooling

調査の方向性

提案されている BOOST_CORE_SATURATE_CAST_HPP の実装、C++26 の saturate_cast リファレンス、および記載されている boost::is_integer 依存関係をレビューしてください。まず、このユーティリティを boost::core に置くべきか、また従う必要がある既存の Boost の規約を判断してください。完了条件は、ライブラリ内の配置場所について合意し、示されている変換を適切にカバーする、互換性のある飽和整数キャストユーティリティを用意することです。

索引モデルが issue の本文から書いたものです。

説明

With C++26, there is std::saturate_cast https://en.cppreference.com/w/cpp/numeric/saturate_cast.html
Can you provide this as well?
I'm not sure if boost::core is the right library.
My implementation requires boost::is_integer (https://github.com/boostorg/type_traits/issues/186), but they didn't understand what I meant and therefore rejected/closed it.

//	Distributed under the Boost Software License Version 1.0 https://www.boost.org/LICENSE_1_0.txt
//	Copyright Gero Peterhoff

#ifndef BOOST_CORE_SATURATE_CAST_HPP
#define BOOST_CORE_SATURATE_CAST_HPP

#include <boost/type_traits/is_integer.hpp>
#include <limits>



namespace boost
{
namespace core
{
template <typename To, typename From>
inline BOOST_CXX14_CONSTEXPR typename std::enable_if<boost::is_integer<To>::value && boost::is_integer<From>::value, To>::type	saturate_cast(const From& from)	noexcept
{
	using limits = std::numeric_limits<To>;

	BOOST_IF_CONSTEXPR (std::is_same<To, From>::value)
	{
		return from;
	}
	else BOOST_IF_CONSTEXPR (std::is_signed<To>::value && std::is_unsigned<From>::value)
	{
		using type = typename std::make_unsigned<To>::type;
		return
			(from > type(limits::max())) ? limits::max() :
			To(from);
	}
	else BOOST_IF_CONSTEXPR (std::is_unsigned<To>::value && std::is_signed<From>::value)
	{
		using type = typename std::make_unsigned<From>::type;
		return
			(from < 0) ? To{} :
			(type(from) > limits::max()) ? limits::max() :
			To(from);
	}
	else BOOST_IF_CONSTEXPR (std::is_signed<To>::value && std::is_signed<From>::value)
	{
		return
			(from < limits::min()) ? limits::min() :
			(from > limits::max()) ? limits::max() :
			To(from);
	}
	else
	{
		return
			(from > limits::max()) ? limits::max() :
			To(from);
	}
}

}	//	core
}	//	boost

#endif	//	BOOST_CORE_SATURATE_CAST_HPP

thx
Gero

主要言語
C++
スター
156
フォーク
116
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/core のほかの issue

boostorg/core の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。