@@ -385,6 +385,7 @@ struct message {
385385 using num_fields_t = std::integral_constant<std::size_t , sizeof ...(Fields)>;
386386 template <std::size_t I> using nth_field_t = stdx::nth_t <I, Fields...>;
387387
388+ using name_t = stdx::cts_t <Name>;
388389 using env_t = Env;
389390 using access_t = msg_access<Name, Fields...>;
390391 using default_storage_t = typename access_t ::default_storage_t ;
@@ -789,4 +790,37 @@ struct field_locator<Name, Env, Fields...> {
789790
790791template <stdx::ct_string Name, typename ... Ts>
791792using relaxed_message = typename detail::field_locator<Name, Ts...>::msg_type;
793+
794+ namespace detail {
795+ template <typename Msg> struct replace_fields_q {
796+ template <typename ... Fs>
797+ using fn = ::msg::message<Msg::name_t ::value, typename Msg::env_t , Fs...>;
798+ };
799+
800+ template <typename Msg, stdx::ct_string OldName, stdx::ct_string NewName>
801+ struct with_renamed_field {
802+ using split_fields = boost::mp11::mp_partition_q<typename Msg::fields_t ,
803+ matching_name<OldName>>;
804+
805+ using untouched_fs = boost::mp11::mp_second<split_fields>;
806+ static_assert (boost::mp11::mp_count_if_q<untouched_fs,
807+ matching_name<NewName>>::value ==
808+ 0 ,
809+ " rename_field: New field name already exists in message" );
810+
811+ using replaced_fs = boost::mp11::mp_first<split_fields>;
812+ static_assert (not boost::mp11::mp_empty<replaced_fs>::value,
813+ " rename_field: Old field name not found in message" );
814+
815+ using new_f = typename boost::mp11::mp_first<
816+ replaced_fs>::template with_new_name<NewName>;
817+
818+ using new_fields = boost::mp11::mp_push_back<untouched_fs, new_f>;
819+ using msg = boost::mp11::mp_apply_q<replace_fields_q<Msg>, new_fields>;
820+ };
821+ } // namespace detail
822+
823+ template <typename Msg, stdx::ct_string OldName, stdx::ct_string NewName>
824+ using rename_field =
825+ typename detail::with_renamed_field<Msg, OldName, NewName>::msg;
792826} // namespace msg
0 commit comments