在一个只有const shared_ptr的unordered_set中找到一个shared_ptr?

时间:2018-06-08 10:16:09

标签: c++ const unordered-set

我有一个unordered_set<shared_ptr<T>> us,我想知道kus是否在kshared_ptr<T const>类型unordered_set<shared_ptr<T>>::findconst_cast抱怨它无法转换。

有解决方法吗?也许直接提供哈希?

我确实尝试import React from 'react'; import { StatusBar, StyleSheet, Text, View, TouchableOpacity, Animated, Easing, Dimensions } from 'react-native'; import styles from './AppStyleSheet' export default class App extends React.Component { constructor (props) { super(props); let screenWidth = Dimensions.get('window').width, screenHeight = Dimensions.get('window').height; this.state = { MainPosition: [styles.main, {width: screenWidth * 2}, {height: screenHeight}, {marginTop: 0}, {marginLeft: 0}], paneDimensions: [styles.pane, {width: screenWidth}, {height: screenHeight}] } } SlidePane =(direction)=> { let screenHeight = Dimensions.get('window').height, screenWidth = Dimensions.get('window').width, theTopMargin, theLeftMargin; if (direction === 'right') { theLeftMargin = parseInt('-' + screenWidth) } this.setState({ MainPosition: [styles.main, {width: screenWidth * 2}, {height: screenHeight}, {marginTop: 0}, {marginLeft: theLeftMargin}] }) } render() { return ( <View style={this.state.MainPosition}> <StatusBar hidden /> <View style={this.state.paneDimensions}> <View style={styles.buttonsContainer}> <TouchableOpacity style={styles.button} onPress={() => this.SlidePane('right')}> <Text style={styles.buttonText}>Slide Right</Text> </TouchableOpacity> </View> </View> <View style={this.state.paneDimensions}> <Text style={styles.paneText}>Right Pane</Text> </View> </View> ); // end return } // end render } // end export (感觉很脏),但没有削减它。

1 个答案:

答案 0 :(得分:10)

使用std::const_pointer_cast是一种可行的解决方案。

us.find(std::const_pointer_cast<T>(k));

由于你没有修改k,所以可以抛弃const。