[ 
https://issues.apache.org/jira/browse/ARROW-2478?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16448604#comment-16448604
 ] 

ASF GitHub Bot commented on ARROW-2478:
---------------------------------------

pitrou commented on a change in pull request #1937: ARROW-2478: [C++] Introduce 
a checked_cast function that performs a dynamic_cast in debug mode
URL: https://github.com/apache/arrow/pull/1937#discussion_r183486305
 
 

 ##########
 File path: cpp/src/arrow/util/checked_cast.h
 ##########
 @@ -0,0 +1,42 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#ifndef ARROW_CAST_H
+#define ARROW_CAST_H
+
+#include <type_traits>
+
+namespace arrow {
+
+template <typename OutputType, typename InputType>
+OutputType checked_cast(InputType&& value) {
+  static_assert(std::is_class<typename std::remove_pointer<
+                    typename 
std::remove_reference<InputType>::type>::type>::value,
+                "checked_cast input type must be a class");
+  static_assert(std::is_class<typename std::remove_pointer<
+                    typename 
std::remove_reference<OutputType>::type>::type>::value,
+                "checked_cast output type must be a class");
+#ifdef NDEBUG
+  return static_cast<OutputType>(value);
+#else
+  return dynamic_cast<OutputType>(value);
 
 Review comment:
   Indeed if people are building in debug mode they probably want the extra 
safety checks.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [C++] Introduce a checked_cast function that performs a dynamic_cast in debug 
> mode
> ----------------------------------------------------------------------------------
>
>                 Key: ARROW-2478
>                 URL: https://issues.apache.org/jira/browse/ARROW-2478
>             Project: Apache Arrow
>          Issue Type: Improvement
>    Affects Versions: 0.9.0
>            Reporter: Phillip Cloud
>            Assignee: Phillip Cloud
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>
> This would use {{static_cast}} in release mode.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to