Adobe.com
Contents Suites Classes Class Index Member Index

IAIStringUtils.h

Go to the documentation of this file.
00001 /*************************************************************************
00002 *
00003 * ADOBE CONFIDENTIAL
00004 * 
00005 * Copyright 2018 Adobe
00006 * 
00007 * All Rights Reserved.
00008 *
00009 * NOTICE: Adobe permits you to use, modify, and distribute this file in
00010 * accordance with the terms of the Adobe license agreement accompanying
00011 * it. If you have received this file from a source other than Adobe,
00012 * then your use, modification, or distribution of it requires the prior
00013 * written permission of Adobe.
00014 *
00015 **************************************************************************/
00016 
00017 #pragma once
00018 
00019 #include <sstream>
00020 #include <string>
00021 
00022 namespace ai
00023 {
00024         namespace detail
00025         {
00026                 // Base case: No args to stream
00027                 void StreamArgs(std::ostringstream& ss)
00028                 {
00029                 }
00030 
00031                 // Recursively stream each arg in the parameter pack
00032                 template<typename T, typename... Ts>
00033                 void StreamArgs(std::ostringstream& ss, const T& t, const Ts&... ts)
00034                 {
00035                         ss << t;
00036                         StreamArgs(ss, ts...);
00037                 }
00038 
00039         } // namespace detail
00040 
00041         /*
00042         * Stream arbitrary number of arguments to std::string
00043         */
00044         template<typename... Args>
00045         inline std::string StreamArgs(const Args&... args)
00046         {
00047                 std::ostringstream ss;
00048                 // TODO: In C++17, fold expression can be used to expand the pack
00049                 // (ss << ... << args);
00050                 detail::StreamArgs(ss, args...);
00051                 return ss.str();
00052         }
00053 
00054         /*
00055         * Utility to create std::string using ostringstream.
00056         */
00057         template<typename T>
00058         inline std::string to_string(const T& value)
00059         {
00060                 return StreamArgs(value);
00061         }
00062 
00063 } // namespace ai


Contents Suites Classes Class Index Member Index
Adobe Solutions Network
 
Copyright © 2014 Adobe Systems Incorporated. All rights reserved.
Terms of Use Online Privacy Policy Adobe and accessibility Avoid software piracy Permissions and Trademarks